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代码如下 连测试数据都找到试了一遍没有问题居然还wa。。。这是搞哪样。。。。。。 #include<stdio.h> #include<string.h> int mod=0; int main() { char a[200][1000],b[200][1000]; int n,i,basea[200],baseb[200]; char *trans1(char [],int); char *trans2(char [],int); scanf("%d",&n); if(n==0) return 0; for(i=0;i<n;i++) scanf("%d %d %s",&basea[i],&baseb[i],a[i]); for(i=0;i<n;i++) { strcpy(b[i],trans1(a[i],basea[i])); strcpy(b[i],trans2(b[i],baseb[i])); printf("%d %s\n%d %s\n\n",basea[i],a[i],baseb[i],b[i]); } return 0; } char *trans1(char *m,int base) { char *add(char *,char *); char *multi(char a,int t,int base); char result[1000],temp[1000]; char *r; int i,wei=0; for(i=0;i<1000;i++) result[i]=0; while(m[wei]!=0) wei++; for(i=0;i<wei;i++) { strcpy(temp,multi(m[i],wei-i,base)); strcpy(result,add(result,temp)); } r=result; return r; } char *add(char a[],char b[]) { int p,q,i=0,result_add,jinwei=0; char result[1000],*pt; for(i=0;i<1000;i++) result[i]=0; for(p=0;a[p];p++); for(q=0;b[q];q++); if(p>=q) { for(i=0;i<q;i++) { result_add=(a[i]+b[i]+jinwei-96)%10; jinwei=(a[i]+b[i]+jinwei-96)/10; result[i]=result_add+48; } while(i<p) { result_add=(a[i]-48+jinwei)%10; jinwei=(a[i]+jinwei-48)/10; result[i]=result_add+48; i++; } if(jinwei) result[p]=jinwei+48; } else { for(i=0;i<p;i++) { result_add=(a[i]+b[i]+jinwei-96)%10; jinwei=(a[i]+b[i]+jinwei-96)/10; result[i]=result_add+48; } while(i<q) { result_add=(b[i]-48+jinwei)%10; jinwei=(b[i]+jinwei-48)/10; result[i]=result_add+48; i++; } if(jinwei) result[q]=jinwei+48; } pt=result; return pt; } char *multiply(char a[],int num) { int i,p,result_mul=0; char *pt,result[1000]; for(i=0;i<1000;i++) result[i]=0; for(p=0;a[p];p++); for(i=0;i<p;i++) { result_mul=(a[i]-48)*num+result_mul; result[i]=result_mul%10+48; result_mul=result_mul/10; } while(result_mul) { result[i]=result_mul%10+48; result_mul=result_mul/10; i++; } pt=result; return pt; } char *devide(char a[],int num) { char *pt,result[1000]; int i,result_dev=0,p; mod=0; for(p=0;a[p];p++); for(i=0;i<1000;i++) result[i]=0; for(i=p-1;i>=0;i--) { result_dev=(a[i]-48+10*mod)/num; if(result[i+1]==0) result[i]=result_dev?result_dev+48:0; else result[i]=result_dev+48; mod=(a[i]-48+10*mod)%num; } pt=result; return pt; } char *multi(char a,int t,int base) { char result[1000],*pt; int i; char *multiply(char [],int); for(i=0;i<1000;i++) result[i]=0; if(a>='0'&&a<='9') result[0]=a; else if(a>='A'&&a<='Z') { result[0]=(a-55)%10+48; result[1]=(a-55)/10+48; } else if(a>='a'&&a<='z') { result[0]=(a-61)%10+48; result[1]=(a-61)/10+48; } for(i=1;i<t;i++) strcpy(result,multiply(result,base)); pt=result; return pt; } char *trans2(char a[],int base) { char *pt,result[1000],rev[1000],swap; int i,p,m; char *devide(char a[],int num); for(i=0;i<1000;i++) {result[i]=0; rev[i]=0;} strcpy(rev,a); for(i=0;rev[0];i++) { strcpy(rev,devide(rev,base)); if(mod>=0&&mod<=9) result[i]=mod+48; else if(mod>=10&&mod<=35) result[i]=mod+55; else if(mod>=36&&mod<=61) result[i]=mod+61; } p=i/2; m=i; for(i=0;i<p;i++) { swap=result[i]; result[i]=result[m-i-1]; result[m-i-1]=swap; } pt=result; return pt; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator