CF - A. String Building
2, 3可以组成大于等于2和3的一切数,所以除了1以外的情况不需要考虑
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
bool t[N];
int main() {
int t;
cin >> t;
while (t --) {
string s;
cin >> s;
int a = 0, b = 0;
bool tt = false;
for (int i = 0; i < s.size(); i ++) {
if (s[i] == 'a') {
a ++;
if (b == 1) {
printf("No\n");
b = 0, a = 0;
tt = true;
break;
}
b = 0;
}
if (s[i] == 'b') {
b ++;
if (a == 1) {
printf("No\n");
b = 0, a = 0;
tt = true;
break;
}
a = 0;
}
}
if (a == 1) {
printf("No\n");
continue;
} else if (b == 1) {
printf("No\n");
continue;
}
if (!tt)printf("Yes\n");
}
return 0;
}