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 |
跪请各位大牛指正错误试了接近一百个用例了,不知道哪里错了 #include <iostream> #include <cstring> #include <algorithm> using namespace std; int x[1800],y[18],first,second,bit,k; bool compare(){ int i,j=second-1; for(i=first-1;j>=0&&x[i]==y[j];j--,i--); if(j<0) return true; return x[i]>y[j]; } void substract(){ int i,j; for(i=first-second,j=0;j<second;j++,i++){ if(x[i]>=y[j]){ x[i]-=y[j]; }else{ x[i]+=k; x[i+1]--; x[i]-=y[j]; } } } int main(){ int i,j; char a[1800],b[30]; while(scanf("%d",&k)&&k){ scanf("%s %s",a,b); first=strlen(a); second=strlen(b); for(i=0;i<first;i++){ x[i]=a[first-1-i]-'0'; } for(i=0;i<second;i++){ y[i]=b[second-i-1]-'0'; } while(first>=second){ while(compare()){ substract(); } if(x[first-1]>0){ x[first-2]+=k*x[first-1]; x[first-1]=0; first--; } while(first>0&&(x[first-1]==0)) first--; } for(i=0;i<first;i++){ x[i+1]+=x[i]/k; x[i]%=k; } for(i=first+30;i>=0&&x[i]==0;i--); first=i+1; memset(a,0,sizeof(a)); for(i=0;i<first;i++){ a[i]=x[first-i-1]+'0'; } if(first==0){ a[0]='0'; } printf("%s\n",a); } system("PAUSE"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator