Codeforces Round #306 (Div. 2)
最近是怎麼了,老是掉分,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