atcoder Cut and Count(简单模拟题)

题意:让输入一个长为n的字符串,让它一分为二使得两边不同字母相同的达到最多

#include <iostream>
#include <cstring>
#include <map>

using namespace std;

int n;
int ans=0;
char s[100+10];
map<char,int>mp;

int main()
{
    cin>>n;
    cin>>s;
    for(int i=1;i<n;i++)
    {
        int num=0;
        for(int j=0;j<=i;j++) mp[s[j]]++;
        for(int j=i+1;j<n;j++)
        {
            if(mp[s[j]]) {
                    num++;
                    mp[s[j]]=0;
            }
        }
        ans=max(num,ans);
        mp.clear();
    }
    cout<<ans<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Fy1999/p/9107893.html
cut
今日推荐