oj 1002题 (大数题)

#include <stdio.h> #include <string.h> int main(void)
{ int q,j,h,k,l; int d; char s1[1001],s2[1001];//题目要求位数不大于1000  scanf("%d",&h); for(l=1;l<=h;l++){ int c[1001]={0}, a[1001]={0},b[1001]={0};//这样可以令数组内全部元素为0  scanf("%s %s",&s1,&s2); int cd1,cd2,cd3,cdmax,cdmin;
        cd1=strlen(s1);
        cd2=strlen(s2);
        cdmax=cd1>cd2?cd1:cd2; for(q=0,j=cd1;q<cd1;q++,j--)
            a[q]=s1[j-1]-48; for(q=0,j=cd2;q<cd2;q++,j--)
            b[q]=s2[j-1]-48; for(k=0,d=0;k<cdmax;k++)
        {
            c[k]=(a[k]+b[k]+d)%10; //个个位相加满十进一  d=(a[k]+b[k]+d)/10;
         } 
         printf("Case %d:\n%s +%s =",l,s1,s2); if(d!=0){//判断最后一位和是否大于一  c[cdmax]=1; for(cd3=cdmax;cd3>=0;cd3--){
                 printf("%d",c[cd3]);
             }
         } else{ for(cd3=cdmax-1;cd3>=0;cd3--){
                 printf("%d",c[cd3]);
             }
         } if(l!=h)//最后跳一行  printf("\n\n"); else printf("\n");
    } return 0;
}

题目:

Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.


Input 一致                   确定的
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
处理 1000以内 ,即使double longlong 也无法满足


Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases. 方程


Sample Input
2 1 2 112233445566778899 998877665544332211


Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
方法步骤:将数字以字符串的方式存储,在单个位相加(用10取余),满十进一(除10),注意初始化(对前几位数赋值,后面直接默认赋0)
全部评论

相关推荐

程序员牛肉:继续沉淀吧同学,你这就是纯纯的流水线产品。 差不多的学历+两个烂大街项目。自身学历又不行,现在找啥实习呢。有点太浮躁了。多花点心思搞搞ai,开源和八股。这比你这段时间捣鼓一段小厂实习要好得多;
点赞 评论 收藏
分享
想进开水团喝开水:哦 给我一个 就算你真拿到牛友也会为你开心的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务