Analog decimal Power
Decimal Place POS
Not 0 Bottom E
Length Len
There are only three cases
POS > Len
POS < E
E < POS < Len
1#include <iostream>2#include <cstring>3 using namespacestd;4 inta[ -], b[ -], c[ -];5 voidCal ()6 {7Memset (c,0,sizeof(c)); 8 for(inti =0; I < $; i++)9 for(intj =0; J <Ten; J + +)TenC[I+J] + = a[i] *B[j]; One for(inti =0; I < $; i++){ Ac[i+1] + = c[i]/Ten; -C[i]%=Ten; - } theMemset (A,0,sizeof(a)); - for(inti =0; I <= $; i++) -A[i] =C[i]; - } + Chars[Ten]; - intPOS, N, Len; + intMain () A { at while(cin>>s>>N) - { -Memset (A,0,sizeof(a)); -memset (b,0,sizeof(b)); -Memset (c,0,sizeof(c)); - intt =0; in for(inti =5; I >=0; i--) - { to if(s[i]=='.') pos =i; + Elseb[t++] = s[i]-'0'; - } thea[0] =1; * for(inti =1; I <= N; i++) Cal (); $Len = $;Panax Notoginseng while(!c[len] && len>=0) len--; - intE =0;//End the while(!c[e] && e<= len) e++; +pos =5-Pos; POS *= N;//decimal point A if(Pos >len) the { +cout<<"."; - for(inti = pos-1; I >= e; i--) cout<<C[i]; $cout<<Endl; $ } - Else if(POS <= e)//integer - { the for(inti = len; I >= pos; i--) cout<<C[i]; -cout<<Endl;Wuyi } the Else//Normal - { Wu for(inti = len; I >= pos; i--) cout<<C[i]; -cout<<"."; About for(inti = pos-1; I >= e; i--) cout<<C[i]; $cout<<Endl; - } - } -}
POJ 1001 exponentiation Analog Fractional Power