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 |
很麻烦的题目,贴出代码(G++)#include "cstdio" #include "cstring" char ans[100]; int main() { char r[10]; int n,bit,num,i,d,j,temp,e,len; bool flag; while(scanf("%s%d",r,&n)==2) { len=strlen(r); bit=0; flag=false; for(i=0;r[i];i++) { if(flag) bit++; if(r[i]=='.') flag=true; } bit*=n; num=0; for(i=0;i<300;i++) ans[i]=0; for(i=0;i<6&&r[i];i++) if(r[i]>='0'&&r[i]<='9') num=num*10+r[i]-'0'; temp=num; for(i=0;temp;i++) { ans[i]=temp%10+'0'; temp/=10; } for(i=1;i<n;i++) { d=0; for(j=0;ans[j];j++) { e=(ans[j]-'0')*num+d; ans[j]=e%10+'0'; d=e/10; } while(d) { ans[j++]=d%10+'0'; d/=10; } } if(n>1) len=j; else len=strlen(ans); for(i=0;i<len&&ans[i];i++) { if(ans[i]=='0'&&i<bit) continue; else { ans[i-1]=0; break; } } if(bit>=len) { putchar('.'); while(bit>len) { putchar('0'); bit--; } for(i=len-1;i>=0&&ans[i];i--) putchar(ans[i]); printf("\n"); } else { for(i=len-1;i>=0&&ans[i];i--) { putchar(ans[i]); if(i==bit&&ans[i-1]) putchar('.'); } 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