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<stdio.h> #include<string.h> char a[1005]; char b[1005]; char c[1005]; int main() { int i,n,len1,len2,j,max,min,t; char ch; scanf("%d",&n); for(i=0;i<n;i++) { t=0; scanf("%s %s",a,b); len1=strlen(a); len2=strlen(b); for(j=0;j<len1/2;j++) { ch=a[j]; a[j]=a[len1-j-1]; a[len1-j-1]=ch; } for(j=0;j<len2/2;j++) { ch=b[j]; b[j]=b[len2-j-1]; b[len2-j-1]=ch; } max=len1>len2?len1:len2; min=len1+len2-max; for(j=0;j<min;j++) { t=t+a[j]+b[j]-'0'-'0'; c[j]=t%2+'0'; t/=2; } for(j=min;j<max;j++) { t=t+a[j]+b[j]-'0'; c[j]=t%2+'0'; t/=2; } if(t==1) c[max]='1'; else c[max]='0'; printf("%d ",i+1); for(j=max;j>=0;j--) if(c[j]!='0') { printf("%c",c[j]); --j; break; } for(;j>=1;j--) printf("%c",c[j]); printf("%c",c[0]); printf("\n"); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator