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)
全部评论

相关推荐

NBA球星伦纳德:jd是这样的,工作连拧螺丝都算不上
点赞 评论 收藏
分享
03-05 17:03
已编辑
浙江工商大学 C++
陈好好wy:整体看下来有点空空的感觉,可以把每一段项目经历都再完善一下,然后用小标题的形式写个两到三条,目前看有点太简单了,不太能看出具体在这个项目里做了什么工作。还是要尽量把自己做的工作以量化的形式体现在简历上呢。
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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