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 <stdio.h> #include <iostream> using namespace std; int f(int *a,int n,int mm){ int c=0,m=0; int sum=1; a[0]=1; for (int i = 0;i<mm;++i){ c=0; for (int j=0;j<=m;++j){ a[j]=a[j]*n+c; c=a[j]/10000; a[j]%=10000; } if (c>0){ while(c>=10000){ a[++m]=c%10000; c=c/10000; } if(c>0) a[++m]=c; } } return m; } int main() { char str[10]; int power; int number=0; int ans[100]; int start,end,reN; while(scanf("%s%d",str,&power)==2){ //printf("%s %d\n",str,power); //for(int i=0;i<10;++i) printf("%d\t",str[i]); number=0; int ii,ispoint=0; for( ii=0;str[ii]!=0;++ii){ if(str[ii]=='.'){ ispoint=ii;continue;} number=number*10+(str[ii]-'0'); } //printf("number is %d\n",number); //system("pause"); start=f(ans,number,power); //printf("start is %d\n",start); //system("pause"); if(ans[start]/10==0) reN=start*4+1; else if(ans[start]/100==0) reN=start*4+2; else if(ans[start]/1000==0) reN=start*4+3; else if(ans[start]/10000==0) reN=start*4+4; //printf("ren is %d\n",reN); for(int i=0;1;++i){ if(ans[i]!=0){ end=i; break; } } //printf("end is %d\n",end); //system("pause"); int *Ans=new int[(start-end+1)*4+100]; int len=-1; for(int i=start;i>=end;--i){ Ans[++len]=ans[i]/1000; Ans[++len]=(ans[i]/100)%10; Ans[++len]=(ans[i]/10)%10; Ans[++len]=ans[i]%10; } for(int i=0;1;++i){ if(Ans[i]!=0){ start=i; break; } } for(int i=len;1;--i){ if(Ans[i]!=0){ end=i; break; } } if(ispoint!=0){ bool flag=0; for(int i=ispoint+1;i<ii;++i){ if(str[i]!='0'){ flag=1; break; } } if(flag) ispoint=1; else{ispoint=0;} } if(ispoint==0) { //printf("<<<<"); for(int i=start;i<=end;++i){printf("%d",Ans[i]);} } else{ if(str[0]=='0'){ reN=(ii-2)*power-reN; //printf("renn is %d\n",reN); printf("."); for(int i=0;i<reN;++i) printf("0"); for(int i=start;i<=end;++i){printf("%d",Ans[i]);} } else{ //printf(">>>>>\n"); if(str[1]=='.'){reN=reN-(ii-2)*power;} else{reN=reN-(ii-3)*power;} //printf("renn is %d\n",reN); for(int i=start;i<start+reN;++i){printf("%d",Ans[i]);} printf("."); for(int i=start+reN;i<=end;++i){printf("%d",Ans[i]);} } } printf("\n"); delete []Ans; } //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