zoukankan      html  css  js  c++  java
  • A

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    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.

    Sample Input

    Input
    ABA
    Output
    NO
    Input
    BACFAB
    Output
    YES
    Input
    AXBYBXA
    Output
    NO

    Hint

    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".

    题意:

    给定一字符串,求能否找出“AB”“BA”两不重叠字符串。

    啊啊啊,坑比的字符串题!!卡了三组数据TAT

    附AC代码:

     1 #include<iostream>
     2 #include<cstring>
     3 using namespace std;
     4 
     5 int main(){
     6     string s;
     7     int t=-1,v=-1,ans,temp,x,y,a,b,c,d;
     8     cin>>s;
     9     int len=s.size();
    10     ans=0;
    11     temp=0;
    12     x=0;
    13     y=0;
    14     for(int i=0;i<len;i++){
    15         if(s[i]=='A'&&s[i+1]=='B'){
    16             if(i!=t&&!ans){
    17                 ans++;
    18                 t=i+1;
    19                 a=i;
    20                 break;
    21             }
    22         }
    23     }
    24     for(int i=0;i<len;i++){
    25         if(s[i]=='B'&&s[i+1]=='A'){
    26             if(i!=t&&i+1!=a&&!temp){
    27                 temp++;
    28                 t=i+1;
    29                 break;
    30             }    
    31         }
    32     }
    33     for(int i=0;i<len;i++){
    34         if(s[i]=='B'&&s[i+1]=='A'){
    35             if(i!=v&&!x){
    36                 x++;
    37                 v=i+1;
    38                 b=i;
    39                 break;
    40             }    
    41         }
    42     }
    43     for(int i=0;i<len;i++){
    44         if(s[i]=='A'&&s[i+1]=='B'){
    45             if(i!=v&&i+1!=b&&!y){
    46                 y++;
    47                 v=i+1;
    48                 break;
    49             }
    50         }
    51     }
    52     if(ans&&temp){
    53         cout<<"YES"<<endl;
    54         return 0;
    55     }
    56     else if(x&&y){
    57         cout<<"YES"<<endl;
    58         return 0;
    59     }
    60     cout<<"NO"<<endl;
    61     return 0;
    62 } 
  • 相关阅读:
    androidstudio gradle下载速度慢
    paddlex 使用-11 实例图像分割
    paddlex 使用-10 语义图像分割
    redis C# Windows下测试环境
    CSS Flex弹性布局(多个div自动换行)
    扩展排序后重新编号
    纯css制作的打勾(√)小图标
    layui表格-template模板的三种用法
    VB中各种数据类型转换函数
    将ACCESS 的数据库中的表的文件 导出了EXCEL格式
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5720419.html
Copyright © 2011-2022 走看看