zoukankan      html  css  js  c++  java
  • Codeforces Round #306 (Div. 2) A. Two Substrings【字符串/判断所给的字符串中是否包含不重叠的“BA” “AB”两个字符串】

    A. Two Substrings
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

    Input

    The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

    Output

    Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

    Examples
    input
    ABA
    output
    NO
    input
    BACFAB
    output
    YES
    input
    AXBYBXA
    output
    NO
    Note

    In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

    In the second sample test there are the following occurrences of the substrings: BACFAB.

    In the third sample test there is no substring "AB" nor substring "BA".

    【分析】:strstr函数判断AB和BA。

    strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串。如果是,则该函数返回str2在str1中首次出现的地址;否则,返回NULL。

    【代码】:

    #include<bits/stdc++.h>
    using namespace std;
    char str[200000],*p;
    int main()
    {
        cin>>str;
        if( (p=strstr(str,"AB")) && (strstr(p+2,"BA")) ) puts("YES");
        else if( (p=strstr(str,"BA")) && strstr(p+2,"AB") ) puts("YES");
        else puts("NO");
        return 0;
    }
    View Code
  • 相关阅读:
    怎么统计指定文件夹下含有.xml格式的文件数目
    SQLServer触发器创建、删除、修改、查看
    Devexpress 学习不错的网址
    Devexpress
    SQL 查找重复项及批量修改数据成固定格式
    elementui carousel不能自适应问题
    node中console自定义样式
    forEach for for in for of性能问题
    骚东西
    关于arr.map()问题
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7953907.html
Copyright © 2011-2022 走看看