Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

测试数据都通过了。各位大哥帮一下忙啊,小妹感恩不尽!

Posted by lucy_whu at 2007-12-26 18:30:52 on Problem 1504
#include<iostream>
using namespace std;
int main()
{
    int t;
    char a[1000],b[1000],c[1000];
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        int lena,lenb;
        lena=strlen(a);
        lenb=strlen(b);
        int i;
        if(lena<lenb)
        {
            for(i=lena;i<lenb;i++)
                a[i]='0';
            a[i]='\0';
        }
        else
        {
            for(i=lenb;i<lena;i++)
                b[i]='0';
            b[i]='\0';
        }
        int s=0,tmp;
        for(i=0;a[i];i++)
        {
            tmp=a[i];
            a[i]=(tmp-'0'+b[i]-'0'+s)%10+'0';
            s=(tmp-'0'+b[i]-'0'+s)/10;
        }
        a[i++]=s+'0';
        a[i]='\0';
        for(i=lena;;i--)
            if(a[i]!='0')break;
        a[i+1]='\0';
        for(i=0;;i++)
            if(a[i]!='0')break;
        cout<<a+i<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator