Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
173666 徐启善(C班) 国债计算 C++ 编译错误 0 0 MS 0 KB 1538 2024-08-20 23:23:33

Tests(0/0):


#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 res = res; if (res.length() <= c) { res = string(c - res.length(), '0') + res; } res.insert(res.length() - c, "."); res.erase(res.find_last_not_of('0') + 1, string::npos); if (res.back() == '.') { res.pop_back(); } cout << res << endl; } return 0; }


测评信息: