CodeForces——Game with string(STL stack栈)

Posted tonyyy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces——Game with string(STL stack栈)相关的知识,希望对你有一定的参考价值。

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
 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栈)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces451A-Game With Sticks-思维

Codeforces Round #643 (Div. 2) D. Game With Array(构造)

Codeforces Round #643 (Div. 2) D. Game With Array(构造)

codeforces 850C Arpa and a game with Mojtaba

Codeforces 354B dp Game with Strings dp

[Codeforces 919F]A Game With Numbers