Codeforces Round 968 (Div. 2)

#include <iostream>
#include <string>

using namespace std;

// 函数 is 用于检查给定的字符串 s 是否满足条件
bool is(const string &s) {
    // 遍历字符串 s 中的每个子串
    for (int i = 1; i < s.length(); ++i) {
        // 从字符串 s 中获取两个子串 t1 和 t2
        string t1 = s.substr(0, i);  // t1 是从开始到第 i 个字符的子串
        string t2 = s.substr(i);     // t2 是从第 i 个字符到末尾的子串

        // 检查 t1 的第一个字符是否等于 t2 的最后一个字符
        // 如果相等,说明存在相邻元素之间的差值不满足递增的条件
        if (t1.front() == t2.back()) {
            return false;  // 返回 false,表示字符串不满足条件
        }
    }
    // 如果所有子串都满足条件,返回 true
    return true;
}

int main() {
    int t;
    cin >> t;  // 读取测试用例的数量
    while (t--) {
        int n;  // 字符串的长度
        cin >> n;
        string s;  // 存储字符串 s
        cin >> s;  // 读取字符串 s

        // 调用函数 is 检查字符串 s 是否满足条件
        if (is(s)) {
            cout << "YES" << endl;  // 如果满足条件,输出 "YES"
        } else {
            cout << "NO" << endl;  // 如果不满足条件,输出 "NO"
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值