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 <string> using namespace std; const int N=1000; string s; int n,a[N+1],a1[N+1],c[N+1],ct,ct1,n1; int zsmultiply(int ct1,int ws) { int i,j,size; if(n1==1) return ct1; size=ct1; for(i=1;i<=size;i++) for (j=1;j<=ws;j++) c[i+j-1]+=a[i]*a1[j]; // cout<<a[1]<<a1[1]; // for(i=size;i>=1;i--) // cout<<c[i]<<"jinru"; // cout<<endl; // return 0; for(i=1;i<=size*2-1;i++) { c[i+1]+=c[i]/10; c[i]=c[i]%10; } size=size*2; while(c[1]==0) { size--; for(i=1;i<=ct1;i++) c[i]=c[i+1]; } while(c[size]==0) size--; // for(i=size;i>=1;i--) // cout<<c[i]; // cout<<endl; for (i=1;i<=size;i++) a[i]=c[i]; return size; } void output(int ct) { int i; // cout<<"ct="<<ct<<" ct1="<<ct1<<endl; // for(i=ct1;i>=1;i--) // cout<<a[i]; // cout<<endl; // cout<<"ct="<<ct<<" ct1="<<ct1<<endl; // return; if(ct>ct1) //小数位数>乘得的位数 { cout<<'.'; for(i=1;i<=ct-ct1;i++) cout<<'0'; } for(i=ct1;i>=1;i--) { if(i==ct) cout<<'.'; cout<<a[i]; } cout<<endl; } int main() { while(cin>>s>>n) { int i,count=0; n1=n; memset(a,0,sizeof(a)); memset(a1,0,sizeof(a1)); memset(c,0,sizeof(c)); for (i=0;i<6;i++) //找小数点 if (s[i]=='.') { count=i+1; break; } ct1=5; //ct1记录数字位数 ct=6-count; //ct记录小数位数 if(count==0) { ct1=6; ct=0; } int j=1; i=1; while(j<=6) { if(s[6-j]!='.') { a[i]=s[6-j]-'0'; //将字符转为数字并倒序存储 j++; i++; } else j++; } //输入正确 输入95.000得到i=ct1---1,a[i]=95000 while(a[1]==0&&count!=0&&ct1>0) //去除小数末尾多余的0 { ct--; ct1--; for(i=1;i<=ct1;i++) a[i]=a[i+1]; } while(a[ct1]==0&&count-1>=1&&ct1>0) //去除整数前面多余的0 { ct1--; count--; } for(i=1;i<=ct1;i++) a1[i]=a[i]; int ws=ct1; //输入正确 输入00.010得到01 // for(i=ct1;i>=1;i--) // cout<<a[i]<<a1[i]; // cout<<ct1<<n<<endl; // break; if(ct1!=0) { while(n1>=1) { ct1=zsmultiply(ct1,ws); memset(c,0,sizeof(c)); n1--; } int temp=ct; for(i=1;i<n;i++) temp+=ct; while(a[ct1]==0) ct1--; output(temp); } else cout<<'0'<<endl; } return 0; } Followed by:
Post your reply here: |