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 */ { ... }
/******************************************************************************** * Copyright(C): * Filename : main.cc * Author : * Version : * Data : * Description : *********************************************************************************/ #include <iostream> #include <iomanip> #include <string> #include <cstdlib> using namespace std; int n,m,s,v; int len; string str; //--------------------------------------------- // main // // int main(int argc, char **argv){ int a,i,pos; while( cin>>str>>m ){ long long int res[5000] = {0}; pos = 0; if ( (pos = str.find('.')) != string::npos ){ // 将末尾的0去掉 while( str[(len=str.length())-1] == '0'){ str.erase(len-1,1); } // 去掉小数点 str.erase(pos,1); // 计算最终结果的精度 pos = (str.length()-pos)*m; } n = atoi(str.c_str()); res[0] = 1; s = 1; v = 0; for ( a=0; a<m; a++ ){ for ( i=0; i<s; i++ ){ res[i] = res[i]*n+v; v = res[i]/10; res[i] = res[i]%10; if ( (v!=0) && (i+1==s) ){ s++; } } } if ( pos >= s ){ cout << '.' ; for ( i=pos-1; i>=s; i-- ){ cout << '0' ; } } int end = 0; if ( pos > 0 ){ i = 0; while( res[i] == 0 ){ end++; i++; } } for ( i=s-1; i>=end; i-- ){ cout << res[i]; if ( i == pos && i!=0 ){ cout << '.' ; } } cout << endl; str.clear(); } cout << endl; }