Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
173689 | B班 李文乐 | 国债计算 | C++ | 无测评数据 | 0 | 0 MS | 0 KB | 2826 | 2024-08-21 07:55:34 |
#include<bits/stdc++.h> using namespace std; string multiple(string a, string b){ int i, j; string result = "0"; for(i = a.length() - 1; i >= 0; i--) { int remain = 0; string str = ""; for(j = b.length() - 1; j >= 0; j--) { int tmp = (a[i] - '0') * (b[j] - '0') + remain; remain = tmp / 10; str = (char)(tmp % 10 + '0') + str; } if(remain != 0) { str = (char)(remain + '0') + str; } int tmp = 0; int m = result.length() - (a.length() - i); int n = str.length() - 1; remain = 0; while(m >= 0 && n >= 0) { tmp = (result[m] - '0') + (str[n] - '0') + remain; remain = tmp / 10; result[m] = (char)(tmp % 10 + '0'); m--; n--; } while(m >= 0) { tmp = (result[m] - '0') + remain; remain = tmp / 10; result[m] = (char)(tmp % 10 + '0'); m--; } while(n >= 0) { tmp = (str[n] - '0') + remain; remain = tmp / 10; result = (char)(tmp % 10 + '0') + result; n--; } if(remain != 0) { result = (char)(remain + '0') + result; } } return result; } int main() { int n, i, j; string str; while(cin >> str >> n) { string res = ""; int pos = str.find_first_of("."); if(pos != string::npos) { str.erase(pos, 1); } int num = str.length() - pos; if(n == 1) { res = str; } else { res = multiple(str, str); for(i = 2; i < n; i++) { res = multiple(res, str); } } if(pos == string::npos) { cout << res << endl; continue; } int c = num * n; i = res.length() - 1; string s = ""; while(c > 0 && i >= 0) { s = res[i--] + s; c--; } s = "." + s; for(j = 0; j <= i; j++) { if(res[j] != '0') { s = res.substr(j, i - j + 1) + s; break; } } for(i = s.length() - 1; i >= 0; i--) { if(s[i] == '0') { s.erase(i, 1); } else { break; } } if(s[s.length() - 1] == '.') { s.erase(s.length() - 1, 1); } cout << s << endl; } return 0; }