<分支语句>【Codeforces Round 906 (Div. 2)】B. Qingshan Loves Strings

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

using namespace std; 

typedef long long ll; 

// vector<int> nums; 
bool isYes(string x) {
    for(int i = 1; i < x.size(); ++i) {
        if(x[i] != x[i - 1]) continue; 
        else return false; 
    }
    return true; 
}

int main() {
    int t; 
    cin >> t; 
    while(t--) {
        string s, t; 
        int a; 
        cin >> a >> a; 
        cin >> s >> t; 
        if(s.size() == 1) cout << "Yes" << endl; 
        else {
            if(isYes(s)) cout << "Yes" << endl; 
            else {  // 此时s一定不是好的 
                if(t[0] != t[t.size() - 1] || isYes(t) == false) {
                    cout << "No" << endl;
                }
                else {  // 此时t一定是好的,接下来通过判断首位,来判断是否可插入
                    char sign = '2'; 
                    bool stop = false;  // 是否已经输出
                    for(int i = 1; i < s.size(); ++i) {
                        if(s[i] == s[i - 1] && sign == '2') {
                            sign = s[i]; 
                        }
                        else if(s[i] == sign) continue; 
                        else if(s[i] == s[i - 1] && sign != '2') {  // s中有0和1两种重复
                            stop = true; 
                        }
                    }
                    if(stop == true) cout << "No" << endl;  // s中有0和1两种重复
                    else if(sign != t[0]) cout << "Yes" << endl; 
                    else if(sign == t[0]) cout << "No" << endl; 
                }
            }
        }

    }
    return 0; 
}                               

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值