Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
173669 | 徐启善(C班) | 国债计算 | C++ | 无测评数据 | 0 | 0 MS | 0 KB | 1552 | 2024-08-20 23:26:25 |
#include <bits/stdc++.h> using namespace std; string cf(string a, string b) { int m = a.size(), n = b.size(); if (a == "0" || b == "0") { return "0"; } vector<int> res(m + n, 0); for (int i = m - 1; i >= 0; --i) { for (int j = n - 1; j >= 0; --j) { int mul = (a[i] - '0') * (b[j] - '0'); int p1 = i + j, p2 = i + j + 1; int sum = mul + res[p2]; res[p2] = sum % 10; res[p1] += sum / 10; } } stringstream ss; for (int num : res) { if (!(ss.str().empty() && num == 0)) { ss << num; } } return ss.str().empty() ? "0" : ss.str(); } int main() { string str; int n; while (cin >> str >> n) { int pos = str.find('.'); if (pos != string::npos) { str.erase(pos, 1); } int num = str.length() - pos; string res = str; for (int i = 1; i < n; ++i) { res = cf(res, str); } if (pos == string::npos) { cout << res << endl; continue; } int c = num * n; string res1 = res; if (res1.length() <= c) { res1 = string(c - res1.length(), '0') + res1; } res1.insert(res1.length() - c, "."); res1.erase(res1.find_last_not_of('0') + 1, string::npos); if (res1.back() == '.') { res1.pop_back(); } cout << res1 << endl; } return 0; }