Description
Input
Output
Sample Input
95.123 12 0.4321 20 5.1234 15 6.7592 9 98.999 10 1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721 .00000005148554641076956121994511276767154838481760200726351203835429763013462401 43992025569.928573701266488041146654993318703707511666295476720493953024 29448126.764121021618164430206909037173276672 90429072743629540498.107596019456651774561044010001 1.126825030131969720661201
Hint
C++
while(cin>>s>>n)
{
...
}
c
while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want
/*while(scanf(%s%d",s,&n)!=EOF) //this also work */
{
...
}
#include<iostream> using namespace std; class Digit { public: friend class List; protected: long digit; Digit* prev; Digit* next; }; class List { public: List(int i) :head(0),tail(0),number(0),xiao(0),item(i),num(0) {} ~List() { Digit* p=head; while(p) { head=head->next; delete p; p=head; } } void Send(char* ch) { int i=0,j=5; while(ch[xiao]!='.') xiao++; if(xiao<=5) xiao=5-xiao; else xiao=0; while(ch[i]=='0'||ch[i]=='.') i++; while(ch[j]=='0') j--; xiao=xiao-5+j; while(i<=j) { if(ch[i]!='.') insertToTail(ch[i]); i++; } } void insertToTail(char ch) { if(tail==0) { tail=head=new Digit; head->prev=0; head->next=0; head->digit=ch-'0'; num=num*10+head->digit; } else { tail->next=new Digit; tail->next->prev=tail; tail=tail->next; tail->digit=ch-'0'; tail->next=0; num=num*10+tail->digit; } } void insertToPrev(long num) { head->prev=new Digit; head->prev->next=head; head=head->prev; head->digit=num; head->prev=0; } void Multiply(long n) { Digit* p=head; while(p) { p->digit*=n; p=p->next; } } void Carry() { Digit* p=tail; long tmp=0; while(p) { p->digit+=tmp; tmp=p->digit/10; p->digit%=10; if(tmp && p==head) insertToPrev(0); p=p->prev; } } void Exponenate() { for(int i=1;i<item;i++) { Multiply(num); Carry(); } } void output() { xiao=xiao*item; Digit *p=head; while(p) { number++; p=p->next; } p=head; if(xiao>=number) { cout<<'.'; for(int j=0;j<xiao-number;j++) cout<<'0'; while(p) { cout<<p->digit; p=p->next; } cout<<endl; } else { while(p && number>xiao) { cout<<p->digit; p=p->next; number--; } if(xiao) cout<<'.'; while(p) { cout<<p->digit; p=p->next; } cout<<endl; } } private: Digit* head; Digit* tail; int xiao; int number; long num; int item; }; int main() { char ch[7]; int mici; while(cin>>ch>>mici) { if(mici==0) { cout<<1<<endl; continue; } List numlist(mici); numlist.Send(ch); numlist.Exponenate(); numlist.output(); } return 0; }