标签:mes ble class stack str xmlns test char def
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.
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.
If the first player wins, print "Yes". If the second player wins, print "No".
abacaba
No
iiq
Yes
abba
No
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 int main() 5 { 6 string str; 7 stack<char> s; 8 cin>>str; 9 int num = 0; 10 for(int i=0;i<str.length();i++) 11 { 12 //判断是否为空一定要放在前面 13 if(!s.empty() && str[i]==s.top()) 14 { 15 num++; 16 s.pop(); 17 } 18 else{ 19 s.push(str[i]); 20 } 21 } 22 if(num%2==0) 23 { 24 cout<<"No"<<endl; 25 }else{ 26 cout<<"Yes"<<endl; 27 } 28 return 0; 29 }
CodeForces——Game with string(STL stack栈)
标签:mes ble class stack str xmlns test char def
原文地址:https://www.cnblogs.com/tonyyy/p/10307010.html