HDU 6264 Super-palindrome
Problem Description
比赛题目:
http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf
http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf
Source
Recommend
#include<bits/stdc++.h> using namespace std; #define ll long long const int inf = 0x3f3f3f3f; const int mod = 1000000007; const int maxn = 10000 + 8; int t, num; string s; map<char, int>mp, np; int main() { scanf("%d", &t); while(t--) { mp.clear(); np.clear(); cin >> s; int len = s.size(), maxx1 = 0, maxx2 = 1, sum1= 0, sum2 = 0; for(int i = 0; i < len; i++) { if(i % 2) { if(!mp[s[i]]) mp[s[i]] = 1; else mp[s[i]]++; sum1++; } else if(!(i % 2)) { if(!np[s[i]]) np[s[i]] = 1; else np[s[i]]++; sum2++; } } map<char, int>::iterator i; for(i = mp.begin(); i != mp.end(); i++) if(i->second > maxx1) maxx1 = i->second; for(i = np.begin(); i != np.end(); i++) if(i->second > maxx2) maxx2 = i->second; printf("%d\n", sum1 - maxx1 + sum2 - maxx2); } return 0; }