题目:https://codeforces.com/problemset/problem/1104/B
A 与 B 正在玩一个关于由小写拉丁字符构成的字符串 s 的游戏,每一个人会轮流操作,先 A 后 B,对于每一次操作,操作者需要将 s中的两个连续且相同的字符消除,消除后的字符串由另一个人操作,同样的,对于每一次操作,如果不能找到两个符合要求的字符,那么操作者输。
例如以下情况:
s = ‘‘xaax’’
首先是 A 操作,他只能将 '‘aa’′ 删除,剩下 ′′xx′′,被 B 消除后字符串为空,A 不能找到符合的字符串,故 A输。
AC代码如下:
Examples
inputCopy
abacaba
outputCopy
No
inputCopy
iiq
outputCopy
Yes
inputCopy
abba
outputCopy
No
Note
In the first example the first player is unable to make a turn, so he loses.
In the second example first player turns the string into "q", then second player is unable to move, so he loses.
#include< iostream>
#include< string>
#include< cstdio>
#include< stack>
using namespace std;
int main()
{
string s;
cin>>s;
stack <int>st;
st.push(s[0]);
int ans=0;
for(unsigned int i=1;i<s.size();i++)
{
if(!st.empty())
{
if(s[i]== st.top())
{
ans++;
st.pop();
}
else
st.push(s[i]);
}
else
st.push(s[i]);
}
if(ans== 0||ans%2==0)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
return 0;
}