最近是怎么了,老是掉分,sad = =.......
明明都会做,但一到比赛时,就没有想法了。。。估计是太困了吧。。。
?
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.
Sample test(s) 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".
?
这道题我看了好久,原因呢?我不知道它说的题目意思是两个字符串“AB"和”BA"就可以了,还是要分别都要两个,事后想想,这个愚蠢的问题。。。然后回过头看,wa~,完了,又要掉分了。。。
想法呢:
就是for4遍,首先第一遍是为了先找出AB有没有,然后for第二遍找出BA,记得把AB所在的位置要标记上;
然后如果上面找到两种字符串的话,那么就不用进行下面的语句了,但是没有找到,那么就要for先找出BA,然后就再去找AB,大致与上面找的方法相同。
?
#include
#include
#include
#include
#include