HDU 6264 Super-palindrome

Problem Description
比赛题目:
http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf
 

 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6730 6729 6728 6727 6726 
 
#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;
}

 

posted @ 2019-09-25 19:33  明霞  阅读(144)  评论(0编辑  收藏  举报