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,大虾们帮忙看一下吧,不胜感激#include <iostream> #include <math.h> #include <stdlib.h> using namespace std; int main() { float r; int n,dot,num[200],tem[6],res[6][200],pre; int shi,cal_pre,i,j; int wei[6]; int shit; int mi; int last; char ch[7]; int chp; while (cin>>r>>n) { if (n==0) cout<<1<<endl; else { for (i=0;i<200;i++) num[i]=0; pre=5; if (r>=10) sprintf(ch,"%2.4f",r); else sprintf(ch,"%f",r); if (ch[6]=='0') { chp=0; while (pre>=0) { if (ch[chp]==' ') { pre=-1; } else if (ch[chp]=='.') { dot=pre+1; } else { num[pre--]=(int(ch[chp])-48); tem[pre+1]=num[pre+1]; } chp++; } } else { dot=5; for (i=0;i<5;i++) tem[4-i]=num[4-i]=int(ch[i+2])-48; tem[5]=num[5]=0; } ////////////////////////////////////////////////////////////////////// pre=6; for (mi=1;mi<n;mi++) { cal_pre=0; for (i=0;i<6;i++) { shi=0; while(cal_pre<pre) { res[i][cal_pre]=int((tem[i]*num[cal_pre]+shi)%10); shi=int(int(tem[i]*num[cal_pre]+shi)/10); cal_pre++; } res[i][cal_pre]=shi; if (shi==0) wei[i]=pre; else wei[i]=pre+1; cal_pre=0; } for (i=0;i<6;i++) { if (i==0) { for (j=0;j<wei[i];j++) num[j]=res[0][j]; num[wei[i]]=0; } else { shi=0; for (j=0;j<wei[i];j++) { shit=shi; shi=int((num[j+i]+res[i][j]+shi)/10); num[j+i]=int((num[j+i]+res[i][j]+shit)%10); } if (shi==0) num[j+i]=0; else { num[j+i]=shi; num[j+i+1]=0; } } } pre=wei[5]+5; }// end for dot=dot*n; i=0; while((num[i]==0)&&(i<dot)) i++; if (i<dot) { last=i; j=pre-1; while((num[j]==0)&&(j>=dot)) j--; if (j>=dot) for (;j>=dot;j--) cout<<num[j]; cout<<"."; for (;j>=last;j--) cout<<num[j]; cout<<endl; } else { last=dot; j=pre-1; while((num[j]==0)&&(j>=dot)) j--; if (j<dot) cout<<0; for (;j>=last;j--) cout<<num[j]; cout<<endl; } }//end else } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator