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;
}

 

转载于:https://www.cnblogs.com/RootVount/p/11586894.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值