Codeforces-B-Game with string(模拟栈)
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|≤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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
char a[1000005];
stack<char> s;
int main()
{
scanf("%s",a);
int len=strlen(a);
s.push(a[0]);
int sum=0;
for(int t=1;t<len;t++)
{
if(!s.empty()&&a[t]==s.top())
{
s.pop();
sum++;
continue;
}
else
{
s.push(a[t]);
}
}
if(sum%2==0)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
return 0;
}
Codeforces-B-Game with string(模拟栈)的更多相关文章
- java 16 - 5 LinkedList模拟栈数据结构的集合
请用LinkedList模拟栈数据结构的集合,并测试 题目的意思是: 你自己的定义一个集合类,在这个集合类内部可以使用LinkedList模拟. package cn_LinkedList; impo ...
- 第一回写的用arraylist模拟栈操作
package hashMap; import java.util.ArrayList; import d.Student; /** * 用ArrayList模拟栈操作 * @author zhuji ...
- HDOJ/HDU 1022 Train Problem I(模拟栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- Hdu 3887树状数组+模拟栈
题目链接 Counting Offspring Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- Java连载69-接受输入、用数组模拟栈
一.编写一个酒店管理系统 1.直接上代码 package com.bjpowernode.java_learning; public class D69_1_ { //编写一个程序模拟酒店的管理系 ...
- java模拟栈的操作
栈是一种有序列表,可以使用数组的结构来储存栈的数据内容 思路 1. 创建一个栈类StackArray 2. 定义一个top来模拟栈顶,初始化为-1 3. 入栈: 当有数据加入到栈的时候 top++ s ...
- Stack (30)(模拟栈,输出中间数用set)
Stack is one of the most fundamental data structures, which is based on the principle of Last In Fir ...
- 牛客编程巅峰赛S1第11场 - 黄金&钻石 A.牛牛的01游戏 (模拟栈)
题意:有一个\(01\)串,两个相邻的\(0\)可以变成一个\(1\),两个相邻的\(1\)可以直接消除,问操作后的字符串. 题解:数组模拟栈直接撸,上代码吧. 代码: class Solution ...
- ACM/ICPC 之 用双向链表 or 模拟栈 解“栈混洗”问题-火车调度(TSH OJ - Train)
本篇用双向链表和模拟栈混洗过程两种解答方式具体解答“栈混洗”的应用问题 有关栈混洗的定义和解释在此篇:手记-栈与队列相关 列车调度(Train) 描述 某列车调度站的铁道联接结构如Figure 1所示 ...
随机推荐
- spring中的class配置不能使用properties中的字符串
1.比如在a.properties中我们声明了一个变量: classRoom=com.wc82.ClassRoom 2.然后在spring的配置文件中:applicationContext.xml,有 ...
- Markdown简要规则
We believe that writing is about content, about what you want to say – not about fancy formatting. 我 ...
- AudioManager 音量『转』
获取系统音量 通过程序获取android系统手机的铃声和音量.同样,设置铃声和音量的方法也很简单! 设置音量的方法也很简单,AudioManager提供了方法: publicvoidsetStream ...
- ssh框架整合其他方式(没有hibernate核心配置文件)
- css水平居中,竖直居中技巧(一)
css水平居中,竖直居中技巧(一)===### 1.效果 ### 2.代码#### 2.1.index.html <!DOCTYPE html> <html lang="z ...
- solr search基础知识(控制符及其参数)
1.^ 控制符 (1)查询串上用^ 搜索: 天后王菲,如果希望将王菲的相关度加大,用^控制符. 天后 王菲^10.5 结果就会将含有王菲的document权重加大分数提高,排序靠前,10.5为权重 ...
- 定时node-schedule 模块的使用
You can install using npm. npm install node-schedule var schedule = require('node-schedule'); var j ...
- CodeForces 703C Chris and Road (简单几何)
题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度. ...
- 【Android4高级编程笔记】深入探讨Android Activity
创建Activity 要创建一个新的Activity,需要对Activity类进行扩展,在新类定义用户界面并实现新的功能. 视图是用来显示数据和提高用户交互的Ui控件.Android提供了多个布局类, ...
- springMvc参数传递的方法
package cn.edu.hj.controller; import java.util.Map; import javax.servlet.http.HttpServletRequest; im ...