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

怎么还是wa?

Posted by wwwwwwking at 2008-03-06 14:12:56 on Problem 2845
#include <stdio.h>
#include <string.h>
int main ()
{
    int n,t,i,j,carry,c,d;
    char a[1000],b[1000];
    scanf ("%d",&n);
    for (t=1;t<=n;++t)
    {
        scanf ("%s%s",a,b); 
        c=strlen(a);   
        d=strlen(b);
        carry=0;
        if (c>d)
        {
            j=c-1;
            for (i=d-1;i>=0;--i)
            {
                 a[j]=carry+a[j]+b[i]-48;
                 carry=(a[j]-48)/2;
                 a[j]=(a[j]-48)%2+48;
                 j--;                
            }  
            if (carry)
            {
                  for (i=c-d-1;i>=0;--i)
                  {
                       a[i]+=carry;
                       carry=(a[i]-48)/2;
                       a[i]=(a[i]-48)%2+48;      
                  }          
            } 
            printf ("%d ",t);
            if (carry)
                   printf ("%d",carry);
             for (i=0;i<c-1;++i)
                    if (a[i]-48) break;
             for (;i<c;++i)
                    printf ("%c",a[i]);
             printf ("\n");
        } //endif
        else
        {
            j=d-1;
            for (i=c-1;i>=0;--i)
            {
                 b[j]=carry+b[j]+a[i]-48;
                 carry=(b[j]-48)/2;
                 b[j]=(b[j]-48)%2+48;
                 j--;    
            }  
            if (carry)
            {
                  for (i=d-c-1;i>=0;--i)
                  {
                       b[i]+=carry;
                       carry=(b[i]-48)/2;
                       b[i]=(b[i]-48)%2+48;      
                  }          
            } 
            printf ("%d ",t);
            if (carry)
                   printf ("%d",carry);
             for (i=0;i<c-1;++i)
                    if (b[i]-48) break;
             for (;i<c;++i)
                    printf ("%c",b[i]);
             printf ("\n");
        }
    }
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