Two people are playing a game with a string ss, consisting of lowercase latin letters.
On a player's turn, he should choose two consecutive equal letters in the string and delete them.
For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses.
Your task is to determine which player will win if both play optimally.
Input
The only line contains the string ss, consisting of lowercase latin letters (1≤|s|≤1000001≤|s|≤100000), where |s||s| means the length of a string ss.
Output
If the first player wins, print "Yes". If the second player wins, print "No".
Examples
input
Copy
abacaba
output
Copy
No
input
Copy
iiq
output
Copy
Yes
input
Copy
abba
output
Copy
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 <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
vector<char> ss;
int main() {
string ch;
cin >> ch;
ss.push_back(ch[0]);
int k = 1;
int cnt = 0;
for(int i = 1; i < ch.size(); i++){
if(ch[i] == ss[k - 1] && !ss.empty()){
ss.erase(ss.begin() + k - 1);
k--;
cnt += 2;
}else{
ss.push_back(ch[i]);
k++;
}
}
//cout << ss.size() << " " << ch.size();
if(ss.size() == ch.size()) cout << "No" << endl;
else{
if(ss.empty()){
if((cnt / 2) & 1) cout << "Yes" << endl;
else cout << "No" << endl;
}else{
if((cnt / 2) & 1) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
return 0;
}