| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
WA了。。求解释。#include<iostream> #include<string.h> using namespace std; char s1[100]; char s2[100]; char s[100]; int main() { int i,n,j,l1,l2,max,min,t,sum; scanf("%d",&n); for(i=0;i<n;i++) { t=0; memset(s,0,sizeof(s)); scanf("%s",s1); scanf("%s",s2); l1=strlen(s1); l2=strlen(s2); max=l1>l2?l1:l2; min=l1<l2?l1:l2; for(j=0;j<min;j++) { sum=0; sum+=s1[j]+s2[j]-'0'-'0'+t; s[j]=sum%10+'0'; t=sum/10; } for(;j<max;j++) { sum=0; sum+=s1[j]+s2[j]-'0'+t; s[j]=sum%10+'0'; t=sum/10; } if(t>=1) s[max]=t+'0'; for(j=0;j<=max;j++) if(s[j]!='0') { printf("%c",s[j]); break; } ++j; for(;s[j]!=NULL;j++) printf("%c",s[j]); printf("\n"); } re Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator