Not simply beatiful strings (判断)

Not simply beatiful strings

Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide.

You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.


Input

The only line contains s (1 ≤ |s| ≤ 105) consisting of lowercase latin letters.

Output

Print «Yes» if the string can be split according to the criteria above or «No» otherwise.

Each letter can be printed in arbitrary case.

Examples
Input
ababa
Output
Yes
Input
zzcxx
Output
Yes
Input
yeee
Output
No
Note

In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.

There's no suitable partition in sample case three.

这道题的意思是让我们把一个串分成两部分,使得这两部分子串的每个子串都仅由两种字母组成(这里的子串可以随意选字母组不一定按照原串的顺序)

我没有想到简单的思路,就是一步一步直接判断的,首先我们可以先统计一下整个串的字母种类数,如果只有1种或大于四种一定是不满足的,如aaaaaa再怎么分也不可能满足,而abcde,怎么分都会使得一个子串的中含有三个即以上字母种类

所以答案就在234中,字母种类为2时,必须保证每种字母个数大于等于2,因为要是每种字母在两个子串中都出现,而字母种类为3时,只要有一个种类的字母个数大于等于2即可,即作为那个公共的字母,另外两种字母一个串一种,当四个的时候一定符合,不管字母多少个。

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1e5+10;
int main(){
    char s[maxn];
    scanf("%s",s);
    int vis[27];
    memset(vis,0,sizeof(vis));
    int cnt = 0;
    for(int i = 0; s[i]; i++){
        vis[s[i]-'a']++;
    }
    for(int i = 0; i < 26; i++){
        if(vis[i]) cnt++;
    }
    if(cnt >= 5 || cnt < 2) printf("No\n");
    else{
        if(cnt == 2){
            int flag = 1;
            for(int i = 0; i < 26; i++){
                if(vis[i] == 1){
                    flag = 0;
                    break;
                }
            }
            if(flag) printf("Yes\n");
            else printf("No\n");
        }
        else if(cnt == 3){
            int flag = 0;
            for(int i = 0; i < 26; i++){
                if(vis[i] > 1){
                    flag = 1;
                    break;
                }
            }
            if(flag) printf("Yes\n");
            else printf("No\n");
        }
        else{
            printf("Yes\n");
        }
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值