HDOJ——1002 A+B Problem II

A + B Problem II

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 295229 Accepted Submission(s): 56839

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.

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

大整数加法:字符数组接收,逆序成整形,然后进位相加,前导去掉,再逆序输出

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main(){
    int T;
    char a[1005],b[1005];
    int  x[1005],y[1005];
    int  ans[1005]; 
    scanf("%d",&T);
    for(int k=1;k<=T;k++){
        memset(x,0,sizeof(x));
        memset(y,0,sizeof(y));
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(ans,0,sizeof(ans));


        scanf("%s %s",a,b);
        int len1=strlen(a);
        int len2=strlen(b);
        for(int i=0;i<len1;i++)
            x[i]=a[len1-1-i]-'0';
        for(int i=0;i<len2;i++)
            y[i]=b[len2-1-i]-'0';        //逆序两数 
        int c=0;                        //代表进位 
        for(int i=0;i<len1+1||i<len2+1;i++){
            ans[i]=(x[i]+y[i]+c)%10;
            c=(x[i]+y[i]+c)/10;
        }                                //两者之和可能比原来的位数多1 

        printf("Case %d:\n",k);
        printf("%s + %s = ",a,b);

        int len=len1 > len2? len1 :len2;
        for(int i=len; i>=0;i--){
            if(i==len&&ans[i]==0)
             continue;
            else 
               {
                printf("%d",ans[i]);
               }
        }
        printf("\n");
        if(k!=T)
         printf("\n");  
    }

    return 0;
} 
全部评论

相关推荐

真心劝退测开,这个方向真的不适合普通人,尤其是应届生。我身边这一届同学的情况,说实话已经很说明问题了。后端秋招一开始确实难,但只要技术不是太拉,后面补录、加面、捞人的机会一波接一波,最后基本都能上岸中小厂。而那些一开始就冲测开的,很多到现在还在等消息,甚至直接凉了。最直观的感受就是:测开的坑真的少得可怜。同一批同学里,后端、前端、客户端基本都有大厂&nbsp;offer&nbsp;扎堆的情况,哪怕不是顶级大厂,也能拿到几个中厂保底。但测开呢?泡出来的又有多少呢。不是不努力,是岗位就那么点,连给你复活赛的机会都没有。后端还能互相捞。秋招挂了,春招、补录、内推、转组,总能找到出口。测开一旦挂了,基本就是真的挂了,后面连投的岗位都没几个。目前有些转的人可能拿了几个不错的实习offer,那到秋招呢?hc少就笑不出来了。现在测开也就只有大厂和顶中厂有,小厂就是测试点点点,大厂也很多是点点点,后端起码还有小厂保个底还有人幻想什么先测开再转开发,我只能说太天真了。测开的经历,想转后端或者客户端根本不可能。核心开发经验没有,项目深度不够,面试官一句那你为什么不一开始就做开发基本宣判死刑。反过来,后端、前端干不下去了,转测开却很容易,这已经说明问题了。如果你是普通双非,那更要慎重。测开&nbsp;HC&nbsp;本来就少,筛人还看背景,普通学校在这种极小池子里基本就是陪跑。你用一个最普通的简历,去抢最少的岗位,结果可想而知。再说客户端和前端。很多人看不起前端,觉得卷,觉得不高级,但现实是岗位多、需求稳定、HC&nbsp;实在。客户端更不用说,Android&nbsp;和&nbsp;iOS&nbsp;到现在依然是硬需求,技术路线清晰,工程经验越久越值钱。我身边拿到大厂最多的,反而是客户端和前端,而不是测开。说句难听的,测开不是不能干,但那是给已经没得选的人准备的退路,不是给应届生拿来当首选的。秋招无脑选测开,本质就是用短期好像更容易上岸,换长期被动甚至被锁死。我是真心建议,能选客户端和前端就选客户端前端,再不行就去后端,哪怕多投多卷一点,也比一头扎进测开强得多。等你真正经历一轮秋招、春招、补录之后,就会发现被反复捞的,从来不是测开劝退不是唱衰,是不想看更多人踩已经踩烂的坑。
Java抽象小篮子:这话术换成劝退后端开发一点问题也没有,总有小登冲出来说别人想焊死车门,我寻思车门要真这么容易焊丝还轮得到你们上车吗
计算机有哪些岗位值得去?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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