加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

hdu1002大数相加

发布时间:2020-12-14 04:07:27 所属栏目:大数据 来源:网络整理
导读:? #include ? #include ? #include ? #define N 1000 ? using namespace std; ? ? ? string bigmult(string a,string b) ? { ? ? ? int la,lb,lc,i,j,flag; ? ? ? string c=""; ? ? ? char t; ? ? ? i=la=a.length()-1; ? ? ? j=lb=b.length()-1; ? ? ? flag

? #include
? #include
? #include
? #define N 1000
? using namespace std;
?
?
? string bigmult(string a,string b)
? {
? ? ? int la,lb,lc,i,j,flag;
? ? ? string c="";
? ? ? char t;
? ? ? i=la=a.length()-1;
? ? ? j=lb=b.length()-1;
? ? ? flag=0;
? ? ? while(i>=0&&j>=0)
? ? ? {
? ? ? ? ? t=a[i]+b[j]+flag-'0';
? ? ? ? ? if(t>'9')?
? ? ? ? ? {
? ? ? ? ? ? ? t=t-10;flag=1;
? ? ? ? ? }
? ? ? ? ? else flag=0;
? ? ? ? ? c+=t;
? ? ? ? ? i--;j--;
? ? ? }
? ? ? while(i>=0)
? ? ? {
? ? ? ? ? t=a[i]+flag;
? ? ? ? ? if(t>'9')
? ? ? ? ? {
? ? ? ? ? ? ? t=t-10;flag=1;
? ? ? ? ? }
? ? ? ? ? else flag=0;
? ? ? ? ? c+=t;
? ? ? ? ? i--;
? ? ? }
? ? ? while(j>=0)
? ? ? {
? ? ? ? ? t=b[j]+flag;
? ? ? ? ? if(t>'9')
? ? ? ? ? {
? ? ? ? ? ? ? t=t-10;flag=1;
? ? ? ? ? }
? ? ? ? ? else flag=0;
? ? ? ? ? c+=t;
? ? ? ? ? j--;
? ? ? }
? ? ? if(flag) c+=(flag+'0');
? ? ? lc=c.length();
? ? ? for(i=0,j=lc-1;i
? ? ? {
? ? ? ? ? t=c[i];c[i]=c[j];c[j]=t;
? ? ? }
? ? ? return c;
? }
?

?
? int main()
? {
? ? ? int test,k=1;
? ? ? string a,b;
? ? ? cin>>test;
? ? ? while(test--)
? ? ? {
? ? ? ? ? cin>>a>>b;
? ? ? ? ? cout<<"Case "<<k++<<":"<<endl;
? ? ? ? ? cout<<a<<" + "<<b<<" = "<<bigmult(a,b)<<endl;
? ? ? ? ? if(test)cout<<endl;
? ? ? }
? ? ? return 0;
? }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读