Bored Three-God NBUT 1228

Bored Three-God

                 Time limit  1000 ms                       Memory limit     65535 kB

The bored Three-God get another boring question.

This problem is ask you plus two big nubmer, please help him, when you solve thisproblem you can

speak to Three-God,"Oh, Please give me a diffculte one, this oneis too easy".


Input
There are muti-case
For each case, there are two integers, n, m (0 < n, m < 10^10000).
Output
Calculate two integers' sum
Sample Input
1 1
2 3
10000 100000
Sample Output
2
5
110000
題解:這設麼破oj,竟然需要前導0,我曹,第一次見,WR了幾十次……


輸入時候有前導0,輸出時必須也有……



#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<string>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#define INF 0x3f3f3f3f
#define ll long long
#define For(i,a,b) for(int i=a;i<b;i++)
#define sf(a)  scanf("%d",&a)
#define sff(a,b)  scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int x[10005],y[10005],z[10005];
char a[10005],b[10005];
int main()
{
    while(~scanf("%s%s",a,b))
    {
        mem(z,0);
        mem(x,0);
        mem(y,0);
        int aa=strlen(a);
        int bb=strlen(b);
        int p=0;
        for(int i=aa-1; i>=0; i--)x[p++]=a[i]-'0';
        p=0;
        for(int i=bb-1; i>=0; i--)y[p++]=b[i]-'0';
        int d=0;
        p=max(aa,bb);
        for(int i=0;i<=p; i++)
        {
            int s=x[i]+y[i]+d;
            z[i]=s%10;
            d=s/10;
        }
        if(z[p])printf("%d",z[p]);
//        int flag=-1;
//        for(int i=50004; i>=0; i--)
//            if(z[i])
//            {
//                flag=i;
//                break;
//            }
        for(int i=p-1; i>=0; i--)
            printf("%d",z[i]);
        printf("\n");
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章