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 |
baHunter C++#include <iostream> #include <string.h> #include <algorithm> using namespace std; const int MAXN=10005; struct BigInt{ int e[MAXN],len; int pis; BigInt() { memset(e,0,sizeof(e)); len=0; pis=0; } void set(char s[]) { int pp; for(int i=0;s[i];i++) { if(s[i]=='.') { pp=i; break; } } int l=strlen(s)-1; pis=l-pp; for(int i=l;i>=0;i--) { if(s[i]=='.')continue; e[len++]=s[i]-'0'; } while(e[len-1]==0&&len>1) len--; } BigInt operator*(const BigInt& b) { BigInt res; for(int i=0;i<len;i++) { int up=0; for(int j=0;j<b.len;j++) { int z=(e[i]*b.e[j]+up+res.e[i+j]); res.e[i+j]=z%10; up=z/10; } if(up!=0) res.e[i+b.len]=up; } res.pis=pis+b.pis; res.len=len+b.len; while(res.e[res.len-1]==0&&res.len>1) res.len--; return res; } void print() { int limit=0; while(e[limit]==0&&limit<pis) limit++; if(pis>=len) { cout<<"."; int i; for(int i=pis;i>len;i--) { cout<<0; } for(int i=len-1;i>limit;i--) { cout<<e[i]; } cout<<e[limit]<<endl; } else { for(int i=len-1;i>=pis;i--) { cout<<e[i]; } if(limit<pis) { cout<<"."; for(int i=pis-1;i>limit;i--) { cout<<e[i]; } cout<<e[limit]<<endl; } else cout<<endl; } } void print2() { for(int i=0;i<len-1;i++) { cout<<e[i]; } cout<<e[len-1]<<endl; } }; char buf[MAXN]="1.0"; char a[MAXN],b[MAXN]; int n; int main() { while(cin>>a>>n) { BigInt res,x; res.set(buf); x.set(a); for(int i=0;i<n;i++) { res=res*x; } res.print(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator