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
  • 相关阅读:
    adb shell am pm 用法
    HTML的属性和css基础
    HTML的实际演练2
    HTML的实际演练1
    HTML的标签简介
    HTML的基础知识
    Python之 ---成员修饰符
    Python基础之-----------函数
    Python之-------基础数据类型
    Python之内置函数
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7953907.html
Copyright © 2011-2022 走看看