当日总结
链接:https://ac.nowcoder.com/acm/contest/19850/E
来源:牛客网
牛牛喜欢跟字符串玩耍,他学会了一种新操作:在当前字符串中任意位置(包括开头和结尾)插入子串
ab
ab。
牛牛称一个字符串为 好串,当且仅当它可以通过若干次上述操作从 空串 生成。
例如,
ab
ab、
aabb
aabb、
aababb
aababb 都是好串,而
aab
aab、
ba
ba、
abbb
abbb 不是好串。
现给定一个字符串
𝑠
s,请判断字符串
𝑠
s 是否是好串。
输入描述:
在一行中输入一个仅由小写字母组成字符串
𝑠
s(
1
≦
∣
𝑠
∣
≦
1
0
5
1≦∣s∣≦10
5
)。
输出描述:
如果字符串
𝑠
s 是好串,输出
Good
Good;否则输出
Bad
Bad。
include
include
include
using namespace std;
using ll=long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin>>s;
ll l=s.length();
bool flag=true;
if(l%2!=0)cout<<"Bad";
else{
queue
for(ll i=0;i<l;i++)
{
if(s[i]'a')
q.push(s[i]);
if(s[i]'b')
{
if(q.empty())
{
flag=false;
cout<<"Bad";
break;
}
else{
q.pop();
}
}
}
if(!q.empty())cout<<"Bad";
else if(flag)cout<<"Good";
}
return 0;
}

浙公网安备 33010602011771号