版本比较
题解:P14161 [ICPC 2022 Nanjing R] 完美回文
正文
增加 11 行删除 11 行
24 行未改动2526272829293031323310 行未改动444546474848495051525354545556575758596061626364656566676868697071726 行未改动7980818283838485868788898990919292939495969798999910010110210210310410524 行未改动- 字符统计: a:1, b:2, c:1- 最多出现: b (2次)- 修改次数 = 4 - 2 = 2- 结果: 把a和c改为b,得到"bbbb"
推导第二个xxx- 长度 = 3- 字符统计: x:3- 最多出现: x (3次)10 行未改动
int main() { //ios::sync_with_stdio(false); //cin.tie(nullptr);
int T; cin >> T; while (T--) { string s; cin >> s;
array<int, 26> count{}; //统计26个字母出现的次数 int max_count = 0; // 记录最大出现次数
for (char c : s) { int idx = c - 'a'; count[idx]++; if (count[idx] > max_count) { max_count = count[idx]; } }
cout << s.length() - max_count << '\n'; }
return 0;}```
6 行未改动
int main() { //ios::sync_with_stdio(false); //cin.tie(nullptr);
int T; cin >> T; while (T--) { string s; cin >> s;
map<char, int> count; int max_count = 0;
for (char c : s) { count[c]++; if (count[c] > max_count) { max_count = count[c]; } }
cout << s.length() - max_count << '\n'; }
return 0;}```