Description
无聊的wxa又开始玩字符串了,现在他有一个字符串s,他想知道这个字符串是否含有非重叠AB和BA。(如ABA里AB和BA是重叠的,而ABBA里AB和BA是不重叠的)
Input
输入数据有多组。
每组测试数据有一个字符串s。
Output
如果可以找到AB和BA,输出”yu ye sa wang dai xing”,否则输出”zhen shi ou ba”
Samples
input Copy
ABA
output Copy
zhen shi ou ba
AC代码
#include <stdio.h>
#include <string.h>
int main() {
char s[1000];
while (scanf("%s", s) != EOF) {
int len = strlen(s);
int found = 1, AB = 0, BA = 0;
for (int i = 0; i < len; i++) {
if (s[i] == 'B' && s[i + 1] == 'A') {
BA = 1;
s[i] = ' ';
s[i + 1] = ' ';
break;
}
}
for (int i = 0; i < len; i++) {
if (s[i] == 'A' && s[i + 1] == 'B') {
AB = 1;
break;
}
}
if (AB && BA) {
printf("yu ye sa wang dai xing\n");
}
else {
printf("zhen shi ou ba\n");
}
}
return 0;
}