CodeForces - 955B(用char会超时。。。)

#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = 100100, INF = 0x7fffffff;
string str;
int vis[26];
int main()
{
    cin>> str;
    mem(vis, 0);
    int cnt = 0, ans = 0;
    for(int i=0; i<str.size(); i++)
            vis[str[i] - 'a']++;
    for(int i=0; i<26; i++)
        if(vis[i])
        {
            cnt++;
            if(vis[i] >= 2)
                ans++;
            if(cnt > 4)
            {
                cout<< "No" <<endl;
                return 0;
            }
        }
    if(cnt == 1)
    {
        cout<< "No" <<endl;
    }
    else if(cnt == 2)
    {
        if(ans == 2)
            cout<< "Yes" <<endl;
        else
            cout<< "No" <<endl;
    }
    else if(cnt == 3)
    {
        if(ans)
            cout<< "Yes" <<endl;
        else
            cout<< "No" <<endl;
    }
    else if(cnt == 4)
        cout<< "Yes" <<endl;

    return 0;
}

 

posted @ 2018-08-03 15:09  WTSRUVF  阅读(226)  评论(0编辑  收藏  举报