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

大数相加

发布时间:2020-12-14 03:28:34 所属栏目:大数据 来源:网络整理
导读:#include stdio.h #include string.h #define Size 1001 char a[Size]; char b[Size]; int res[Size]; int main() { ? ? int NumOfTest; ? ? int alen,blen,i,reslen,len,j; ? ? int count; ? ? int up; ? ? while (scanf("%d",NumOfTest)!=EOF) ? ? { ? ? ?
#include <stdio.h> #include <string.h> #define Size 1001 char a[Size]; char b[Size]; int res[Size]; int main() { ? ? int NumOfTest; ? ? int alen,blen,i,reslen,len,j; ? ? int count; ? ? int up; ? ? while (scanf("%d",&NumOfTest)!=EOF) ? ? { ? ? ? ? count=1; ? ? ? ? for (i=0;i<NumOfTest;i++) ? ? ? ? { ? ? ? ? ? ? memset(res,sizeof(res)); ? ? ? ? ? ? scanf("%s%s",a,b); ? ? ? ? ? ? up = 0; ? ? ? ? ? ? alen = strlen(a); ? ? ? ? ? ? blen = strlen(b); ? ? ? ? ? ? reslen = 0; ? ? ? ? ? ? len = (alen>blen?alen:blen)+1; ? ? ? ? ? ? alen-=1; ? ? ? ? ? ? blen-=1; ? ? ? ? ? ? while (len--) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (alen!=-1&&blen!=-1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? res[reslen] = a[alen]-'0'+b[blen]-'0'+up; ? ? ? ? ? ? ? ? ? ? alen--; ? ? ? ? ? ? ? ? ? ? blen--; ? ? ? ? ? ? ? ? ? ? reslen++; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else if (alen==-1&&blen!=-1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? res[reslen] = b[blen]-'0'+up; ? ? ? ? ? ? ? ? ? ? reslen++; ? ? ? ? ? ? ? ? ? ? blen--; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else if (alen!=-1&&blen==-1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? res[reslen] = a[alen]-'0'+up; ? ? ? ? ? ? ? ? ? ? reslen++; ? ? ? ? ? ? ? ? ? ? alen--; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (res[reslen-1]>9) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? res[reslen-1]=res[reslen-1]%10; ? ? ? ? ? ? ? ? ? ? up=1; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? up = 0; ? ? ? ? ? ? ? ? if (alen==-1&&blen==-1&&up == 1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? res[reslen] = 1; ? ? ? ? ? ? ? ? ? ? up=0; ? ? ? ? ? ? ? ? ? ? reslen++; ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? printf("Case %d:/n",count); ? ? ? ? ? ? printf("%s + %s = ",b); ? ? ? ? ? ? if (res[reslen-1]!=0) ? ? ? ? ? ? ? ? printf("%d",res[reslen-1]); ? ? ? ? ? ? for (j=reslen-2;j>=0;j--) ? ? ? ? ? ? ? ? printf("%d",res[j]); ? ? ? ? ? ? if (i!=NumOfTest-1) ? ? ? ? ? ? ? ? printf("/n"); ? ? ? ? ? ? printf("/n"); ? ? ? ? ? ? count++; ? ? ? ? } ? ? } ? ? return 0; }

(编辑:李大同)

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

    推荐文章
      热点阅读