B 90求 debug
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int n = s.size(); s = " " + s; int cnt = 0; for (int i = 1; i <= n / 2; i++) { int j = n - i + 1; if (s[i] != s[j]) cnt++; } if (cnt == 0) { bool flag = true; for (int i = 1; i <= n / 2; i++) { if (s[i] != 'a') { s[i] = s[n - i + 1] = 'a'; flag = false; break; } } if (flag && n % 2 == 1) s[n / 2 + 1] = 'a'; } else if (cnt == 1) { for (int i = 1; i <= n / 2; i++) if (s[i] != s[n - i + 1]) s[i] = s[n - i + 1] = 'a'; } else { for (int i = 1; i <= n / 2; i++) if (s[i] != s[n - i + 1]) s[i] = s[n - i + 1] = min(s[i], s[n - i + 1]); } s = s.substr(1); cout << s << endl; return 0; }
自我感觉分类讨论全了,但是 WA on #9