杭電ACM--1002

http://acm.hdu.edu.cn/showproblem.php?pid=1002

#include<iostream>
#include<string.h>
#define max(a,b) a>b?a:b
using namespace std;
int main()
{
    int s[1002];
    char a[1001],b[1001];
    int t,i,j;
    cin>>t;
    int Case=1;
    while(t--)
    {
        cin>>a>>b;
        int x=strlen(a),y=strlen(b);
        int MAX=max(x,y);
        memset(s,0,sizeof(s));
        j=0;
        for(i=x-1;i>=0;i--)
            s[j++]+=a[i]-'0';
        for(i=y-1,j=0;i>=0;i--,j++)
        {
            s[j]+=b[i]-'0';
        }
        for(i=0;i<MAX;i++)
        {
            if(s[i]>=10)
            {
                s[i]=s[i]%10;
                s[i+1]+=1;
            }
        }
        i=MAX;
        cout<<"Case "<<Case++<<':'<<endl;
        printf("%s + %s = ",a,b);
        while(s[i]==0)i--;
        if(i<0)
            cout<<0<<endl;
        else
        {
   

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