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 |
建议用高精度,这题不要偷懒,附AC代码#include<stdio.h> #include<string.h> #include<memory.h> #define MAX 1000 //1000大了,开20就能AC了 char str[MAX]; int res[3*MAX],cop[3*MAX],cop2[3*MAX]; int main() { int len,pos,i,j,temp,pre,s; while(scanf("%s",str)!=EOF) { len=strlen(str); memset(res,0,sizeof(res)); memset(cop,0,sizeof(cop)); cop[0]=1; pos=0; for(i=2;i<len;i++) { j=s=0; while(j<=pos || s!=0) { s=s*10+cop[j]; cop[j]=s/8; s%=8; j++; } pos=j-1; temp=str[i]-48; for(j=0;j<=pos;j++) cop2[j]=cop[j]*temp; for(j=pos;j>=0;j--) { pre=cop2[j]/10; cop2[j]%=10; if(pre>0) cop2[j-1]+=pre; } for(j=0;j<=pos;j++) res[j]+=cop2[j]; for(j=pos;j>=0;j--) { pre=res[j]/10; res[j]%=10; if(pre>0) res[j-1]+=pre; } } printf("%s [8] = 0.",str); for(i=1;i<=pos;i++) printf("%d",res[i]); printf(" [10]\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