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> using namespace std; int comp(char a[],char b[],char *c); int main() { int n; scanf("%d",&n); int i,j; char a[85],b[85]; char *c=new char [86]; for(i=0;i<n;i++) { scanf("%s%s",a,b); int len=0; len=comp(a,b,c); int flag=0; printf("%d ",i+1); for(j=len;j>0;j--) { if(c[j]=='0') { if(flag==1) printf("0"); } else { printf("%c",c[j]); flag=1; } } if(flag==0) printf("0\n"); else printf("%c\n",c[0]); } return 0; } int comp(char a[],char b[],char *c) { int j; int la=strlen(a); int lb=strlen(b); int x=1; int l=la; int L=lb; if(la>lb) { x=0; l=strlen(b); L=strlen(a); } int p,k,u=0; for(j=l-1;j>=0;j--) { if(x==0) { p=a[j+L-l]-48;k=b[j]-48; c[l-1-j]=(p+k+u)%2+48; u=(p+k+u)/2; } else { p=a[j]-48;k=b[j+L-l]-48; c[l-1-j]=(p+k+u)%2+48; u=(p+k+u)/2; } } for(j=l;j<L;j++) { if(x==0) { p=a[L-j-1]-48;k=0; c[j]=(p+k+u)%2+48; u=(p+k+u)/2; } else { p=0;k=b[L-j-1]-48; c[j]=(p+k+u)%2+48; u=(p+k+u)/2; } } c[L]=u+48; c[L+1]='\0'; return L; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator