0
点赞
收藏
分享

微信扫一扫

Educational Codeforces Round 127 (Rated for Div. 2) 1671A. String Building

穆风1818 2022-04-24 阅读 57
c++算法

题目

A. String Building

思路

定理:互质的两个数 a, b, 凑不出的最大整数是** $ a * b - a - b $ **
因为$ 2 * 3 - 2 - 3 = 1 $,所以只要将字符串分割成多个只有一种字符的,字符串。如果这些单独字符的字符串长度有只为1的。那就不能凑出来这样的字符串

实现

``cpp
#include
#include
#include
#include

using namespace std;

const int N = 2e5 + 10;

int main()
{
int T;
cin >> T;

while(T--)
{
    string str;
    cin >> str;
    
    bool isa = false, flag = true;
    for(int i = 0; i < str.size(); i ++)
    {
        char ch = str[i];
        int j = i, cnt = 0;
        while(j < str.size() && str[j] == ch) cnt ++, j ++;

        if(cnt == 1)
        {
            flag = false;
            break;
        }
        i = j - 1;
    }

    cout << (flag ? "yes" : "no") << endl;
}
return 0;

}

举报

相关推荐

0 条评论