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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当出现错误信息"python: can't open file 'setup.py': [Errno 2 No such file or directory"时,可能的原因是在当前路径下找不到名为"setup.py"的文件。解决这个问题的方法如下: 1. 首先,确认你正在运行的路径下是否存在名为"setup.py"的文件。如果不存在,你需要检查你的文件系统或代码是否正确安装了所需的文件。 2. 如果你确定"setup.py"文件确实存在,但仍然出现错误,那么有可能是文件路径的问题。请确保你正在正确的目录下执行命令。你可以使用"cd"命令进入包含"setup.py"文件的目录,然后再次尝试执行命令。 3. 另外,还需要注意文件路径的格式。在Linux系统中,路径使用"/"作为分隔符,而不是"\\"。请确保你在命令中使用了正确的路径格式。 综上所述,解决这个问题的关键是确认"setup.py"文件的存在,并确保你正在正确的路径下执行命令。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [问题总结python: can‘t open file ‘XXX‘: [Errno 2] No such file or directory](https://blog.csdn.net/weixin_51736742/article/details/119863044)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [python笔记:python调用matlab出现python: can‘t open file ‘setup.py](https://blog.csdn.net/a_beatiful_knife/article/details/117398315)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值