水题 Codeforces Round #306 (Div. 2) A. Two Substrings

 

题目传送门

 1 /*  2  水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES  3 */  4 #include <cstdio>  5 #include <iostream>  6 #include <cstring>  7 #include <cmath>  8 #include <algorithm>  9 #include <vector> 10 #include <map> 11 #include <queue> 12 #include <set> 13 #include <string> 14 #include <stack> 15 using namespace std; 16 17 typedef long long ll; 18 const int MAXN = 1e5 + 10; 19 const int INF = 0x3f3f3f3f; 20 char s[MAXN]; 21 22 int main(void) //Codeforces Round #306 (Div. 2) A. Two Substrings 23 { 24 while (scanf ("%s", s) == 1) 25  { 26 bool ok1 = false, ok2 = false, ok3 = false, ok4 = false; 27 int len = strlen (s); int p = 0; 28 for (int i=0; i<len; ++i) 29  { 30 if (i < len - 1 && !ok1 && s[i] == 'A' && s[i+1] == 'B') 31  { 32 ok1 = true; i++; 33  } 34 else if (i < len - 1 && ok1 && s[i] == 'B' && s[i+1] == 'A') 35  { 36 ok2 = true; break; 37  } 38  } 39 for (int i=0; i<len; ++i) 40  { 41 if (i < len - 1 && !ok3 && s[i] == 'B' && s[i+1] == 'A') 42  { 43 ok3 = true; i++; 44  } 45 else if (i < len - 1 && ok3 && s[i] == 'A' && s[i+1] == 'B') 46  { 47 ok4 = true; break; 48  } 49  } 50 51 if ((ok1 && ok2) || (ok3 && ok4)) puts ("YES"); 52 else puts ("NO"); 53  } 54 55 56 return 0; 57 } 58 59 /* 60 ABA 61 BACFAB 62 AXBYBXA 63 */

 

你可能感兴趣的:(codeforces)