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 |
帮忙看看错在哪里?这么老通不过#include<iostream> #include<string> using namespace std; const int array_length = 1024; int main() { string R; string dest; int n; cin >> R >> n; double R_double = atof(R.c_str()); if(n <= 0 || n > 25)return 0; if(R_double <= 0.0 || R_double >= 99.999) { return 0; } int *arrays = new int[array_length]; int *current = new int[array_length]; int *temp; int point_num; int temp_length; string::size_type pos = R.find('.'); if(pos == string::npos) { point_num = 0; temp_length = R.size()- R.find_first_not_of('0'); temp = new int[temp_length]; int j = 0; for(int i = R.find_first_not_of('0'); i < R.size(); ++i) { temp[j] = R.at(i)- 48; j++; } } else { string delim(".0"); if(R_double > 1) temp_length =R.size() - R.find_first_not_of(delim)-1; else temp_length =R.size() - R.find_first_not_of(delim); temp = new int[temp_length]; point_num = (R.size()-1-(int)pos)*n; int j = 0; for(int i = R.find_first_not_of(delim); i < R.size(); ++i) { if(R.at(i) == '.')continue; temp[j] = R.at(i)- 48; j++; } } for(int i = 0; i < array_length; ++i) { arrays[i] = 0; current[i] = 0; } for(int i = array_length-1; i >= 0; --i) { static int k = temp_length -1; if(k < 0)break; current[i] = temp[k]; k--; } int i_temp; int arr_temp; int arr_sub = array_length - 1; for(int i = 0; i < n-1; ++i) { for(int j = 0; j < temp_length; ++j) { arr_sub = array_length -1; for(int k = array_length -1; k >= 0; --k) { i_temp = temp[j]*current[k]; arrays[arr_sub] += i_temp%10; arrays[arr_sub-1] += i_temp/10; if(arrays[arr_sub] > 9) { arr_temp = arrays[arr_sub]/10; arrays[arr_sub] = arrays[arr_sub]%10; arrays[arr_sub-1] += arr_temp; } arr_sub--; } for(int u = 0; u < array_length; u++) { if(arrays[u] == 0)continue; for(int y = u; y < array_length; y++) { arrays[y-1] = arrays[y]; } arrays[array_length-1] = 0; break; } } for(int i = 0; i < array_length-1; ++i) { current[i+1] = arrays[i]; arrays[i] = 0; } arrays[array_length-1] = 0; } for(int i = 0; i < array_length; ++i) { arrays[i] = current[i]; } for(int i = 0; i < array_length; ++i) { dest.push_back(arrays[i] +48); } if(point_num != 0) { dest.insert(dest.size()-point_num,"."); while(!dest.empty())//删除后面的零 { if(dest.at(dest.size()-1) != 48)break; dest.erase(dest.size()-1,1); } string::size_type pos = dest.find('.'); while(dest.at(0) != '.') { if(dest.at(0) == '0')dest.erase(0,1); else { break; } } //if(dest.at(0) == '.')dest.insert(0,"0"); if(dest.at(dest.size()-1) == '.')dest.erase(dest.size() -1); } else { while(dest.size() > 1) { if(dest.at(0) != 48)break; dest.erase(0,1); } } //输出 cout << dest << endl; delete [] temp; delete [] arrays; delete [] current; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator