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

贴个代码 前0和后0要注意

Posted by shoutz at 2013-04-18 00:22:06 on Problem 1504
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        string s1,s2;
        for(int i=0;i<n;i++)
        {
            cin>>s1>>s2;
            int le=s1.length()<=s2.length()?s1.length():s2.length();
            int a,b,c=0;
            string s3=s1.length()>=s2.length()?s1:s2;
            for(int i=0;i<le;i++)
            {
                a=s1[i]-'0';
                b=s2[i]-'0';

                s3[i]=((a+b+c)%10)+'0';
                c=(a+b+c)/10;

            }
            s3+='0';

            int tem;
            if(c==1)
                {
                    while(c)
                    {
                        tem=s3[le]-'0'+c;
                        s3[le]=tem%10+'0';
                        c=tem/10;

                        le++;

                    }
                }
                {
                   int q=0,h=0;

            for(int i=0;i<s3.length();i++)
                {

                    if(s3[i]!='0')
                    break;
                    q++;
                }
                for(int i=s3.length()-1;i>0;i--)
                {

                    if(s3[i]!='0')
                    break;
                    h++;
                }
                for(;q<s3.length()-h;q++)
                    cout<<s3[q];
                }

            cout<<'\n';
        }
    }
}

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