Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
173649 C班-李梓韬 国债计算 C++ 编译错误 0 0 MS 0 KB 3535 2024-08-20 22:48:16

Tests(0/0):


#include<iostream> #include<string> #include<vector> #include <cmath> using namespace std; char* itoa(int num, char*str, int radix) {/*绱㈠紩琛?/ char index[] = "0123456789ABCDEF"; unsigned unum;/*涓棿鍙橀噺*/ int i = 0, j, k; /*纭畾unum鐨勫€?/ if (radix == 10 && num < 0)/*鍗佽繘鍒惰礋鏁?/ { unum = (unsigned)-num; str[i++] = '-'; } else unum = (unsigned)num;/*鍏朵粬鎯呭喌*/ /*杞崲*/ do { str[i++] = index[unum % (unsigned)radix]; unum /= radix; } while (unum); str[i] = '\0'; /*閫嗗簭*/ if (str[0] == '-')k = 1;/*鍗佽繘鍒惰礋鏁?/ else k = 0; char temp; for (j = k; j <= (i - 1) / 2; j++) { temp = str[j]; str[j] = str[i - 1 + k - j]; str[i - 1 + k - j] = temp; } return str; } string getTimes(string s,string s2) { string res2; vector<string> res; for (int i = s2.size() - 1; i >= 0; i--) { int j = s.size() - 1, shang = 0; string ss; int down = s2[i] - '0'; for (; j >= 0; j--) { int m = s[j] - '0'; int temp = m*down + shang; if (j - 1 == -1) { char s3[25]; ss.insert(0, itoa(temp, s3, 10)); } else ss.insert(ss.begin(), temp % 10 + '0'); shang = temp / 10; } if (res.size() > 0) { int m = res.size(); while (m--) { ss += '0'; } } //cout<<ss<<endl; res.push_back(ss); } int end = res[res.size()-1].size() - 1; for (int m = 0; m < res.size(); m++) { int zero = end - res[m].size() + 1; while (zero--) { res[m].insert(res[m].begin(), '0'); } //cout<<res[m]<<endl; } int shang = 0, sum = 0; end = res[0].size(); while (end--) { sum = 0; for (int m = 0; m < res.size(); m++) { sum += (res[m][end] - '0'); } sum += shang; //cout << sum << endl; if (end - 1 == -1) { char s3[25]; res2.insert(0, itoa(sum, s3, 10)); } else { res2.insert(res2.begin(), sum % 10 + '0'); } shang = sum / 10; } return res2; } int main() { string s, res2; vector<string> res; double s4; int n; while (cin >> s >> n) { int count = 0;//灏忔暟鐐逛綅鏁? //double resl=pow(s4, n); for (string::iterator iter = s.begin(); iter != s.end(); iter++, count++) { if (*iter == '.') { //cout<<"dsdsd"<<endl; count = (s.size() - count - 1)*n; //cout<<count; s.erase(iter); break; } } string s1 = s; if(n>1) s1 = getTimes(s, s); for (int i = 2; i < n; i++) { s1 = getTimes(s1, s); } int point_pos = s1.size() - count; s1.insert(point_pos, "."); if (s1[0] == '0') s1.erase(s1.begin()); while (s1[s1.size()-1] == '0') { s1.erase(s1.end()-1); } if (s1[s1.size() - 1] == '.') { s1.erase(s1.end() - 1); } cout << s1 << endl; } return 0; }


测评信息: