码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces——Game with string(STL stack栈)

时间:2019-01-23 10:39:52      阅读:195      评论:0      收藏:0      [点我收藏+]

标签: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.

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栈)

标签:mes   ble   class   stack   str   xmlns   test   char   def   

原文地址:https://www.cnblogs.com/tonyyy/p/10307010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!