75分求助

P1015 [NOIP1999 普及组] 回文数

@[panrong](/user/1044970) 和楼主差不多,请问楼主知道问题出在哪里吗,我的代码如下 ``` #include <iostream> #include <string> using namespace std; int hw(string a) { int l = a.size(); for (int i = 0; i < l / 2; i++) { if (a[i] != a[l - 1 - i]) { return 0; } } return 1; } string add(string a, string b, int jz) { int l1 = a.size(), l2 = b.size(); if (l1 > l2) { b = string(l1 - l2, '0') + b; } if (l1 < l2) { a = string(l2 - l1, '0') + a; } int cf = 0, temp = 0; string c; int f = max(l1, l2); for (int i = 0; i < f; i++) { temp = a[f - 1 - i] + b[f - 1 - i] + cf - 2 * '0'; cf = temp / jz; temp %= jz; c = char(temp + '0') + c; } if (cf != 0) { c = char(cf + '0') + c; } return c; } string change(string a) { string b; for (int i = a.size() - 1; i >= 0; i--) { b += a[i]; } return b; } int main() { int k; string a; cin >> k >> a; int step = 0; do { if (hw(a)) { cout << step; return 0; } a = add(a, change(a), k); step++; } while (step <= 30); cout << "Impossible!"; return 0; }
by Faded_wind123 @ 2024-04-14 00:13:55


|