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 |
我提交了好多次 都是PE 表达错误 但是我实在是不知道错在哪里 请高手看一眼帮帮我#define MAX 101 #include<iostream> #include<string> #include<string.h> #include<stdio.h> using namespace std; void mul(int a[],int b); int Base(string); int Point(string); void Show(int a[],int); int main() { string s; int n,base,point; int result[MAX]; while(cin>>s>>n) // s="2.0";n=30; { base=Base(s); point=Point(s); memset(result,0,sizeof(result)); result[0]=base%10000; result[1]=base/10000; for(int i=1;i<n;i++) mul(result,base); Show(result,point*n); } return 0; } int Base(string s) { int i; int n=0; for(i=0;i<s.length();i++) { if(s[i]=='.')continue; n=n*10+s[i]-'0'; } for(i=s.length()-1;s[i]=='0';i--) n/=10; return n; } int Point(string s) { int i; int n=0; int c=0; for(i=s.length()-1;s[i]=='0';i--) { c++; } for(i=s.length()-1;s[i]!='.';i--) { n++; } n-=c; return n; } void mul(int r[MAX],int b) { int i; int tmp=0; for(i=0;i<MAX;i++) { tmp=r[i]*b+tmp; r[i]=tmp%10000; tmp=tmp/10000; } } void Show(int r[MAX],int p) { char s[500]; char s1[500]; int i; s[0]=s1[0]='\0'; for(i=MAX-1;r[i]==0;i--); sprintf(s1,"%d",r[i]); i--; strcat(s,s1); for(;i>=0;i--) { sprintf(s1,"%04d",r[i]); strcat(s,s1); } if(p==0) cout<<s<<endl; else if(p<strlen(s)) { for(i=0;i<strlen(s)-p;i++) cout.put(s[i]); cout<<"."; for(;i<strlen(s);i++) cout.put(s[i]); } else { cout<<"."; for(i=0;i<p-strlen(s);i++) { cout<<"0"; } cout<<s; } cout<<endl; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator