zoukankan      html  css  js  c++  java
  • CF550A Two Substrings

    原题链接

    • 题意:求字符串中是否存在一个 (AB)(BA),他们不重叠。
    • 题解:直接把 (BAB)(ABA) 记录数量的同时,转化为别的字符,然后统计 (AB)(BA) 然后判断答案。
    • 代码:
    #include <iostream>
    #include <cstring>
    using namespace std;
    typedef long long ll;
    const int N = 5e5 + 9;
    const ll mod = 1e9 + 7;
    bool vis[N];
    char s[N];
    int main() {
        int ab_cnt = 0;
        int ba_cnt = 0;
        int aba_cnt = 0;
        cin >> (s + 1);
        int n = strlen(s + 1);
        for (int i = 1; i <n-1; i ++) {
            if (s[i] == 'B' && s[i + 1] == 'A' && s[i + 2] == 'B') {
                aba_cnt++;
                s[i] = s[i + 1] = s[i+2] = '?';
            }
            if (s[i] == 'A' && s[i + 1] == 'B' &&s[i + 2] == 'A') {
                aba_cnt++;
                s[i] = s[i + 1] = s[i + 2] = '?';
            }
        }
        for (int i = 1; i < n; i ++) {
            if (s[i] == 'A' && s[ i + 1] == 'B') {
                ab_cnt++;
            } 
            if (s[i] == 'B' && s[i + 1] == 'A')ba_cnt++;
        }
        cout << s << endl;
        if ( (ab_cnt >= 1&&ba_cnt >= 1) || (ab_cnt >=1 && aba_cnt >= 1 )|| (ba_cnt >= 1 && aba_cnt >= 1)||(aba_cnt > 1)){
            cout << "YES
    ";
        } else cout << "NO
    ";
    }
    
  • 相关阅读:
    AddParent
    AddChild
    贝塞尔曲线代码
    顶点纹理shader
    抽象方法与抽象类
    Application类
    布局组件
    C#单例和Unity单例
    Unity&UGUI
    Json解析
  • 原文地址:https://www.cnblogs.com/Xiao-yan/p/14734579.html
Copyright © 2011-2022 走看看