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所示 ...
随机推荐
- 2016上海浦东汽车展览会C+罩杯 车模名单
只能帮你们到这了
- fluent仿真数值错误
- 修改linux内核启动logo及显示位置
转载于:http://blog.chinaunix.net/uid-28458801-id-3484269.html 在此基础上我又添加了我的一些不同的地方,仅供参考 内核版本: 2.6.35.3 l ...
- ASP.NET MVC3 HtmlHelper用法大全
HTML扩展类的所有方法都有2个参数:以textbox为例子public static string TextBox( this HtmlHelper htmlHelper, string name, ...
- linux设置自动获取IP地址
右键单击,选择设置 勾选桥接模式
- 【总结整理】WebGIS学习-thinkGIS(地理常识):
##地图知识 ###地图定义 地图是按照一定的法则,有选择地以二维或多维形式与手段在平面或球面上表示地球(或其它星球)若干现象的图形或图像,它具有严格的数学基础.符号系统.文字注记,并能用地图概括原则 ...
- C++实现筛选法
筛选法 介绍: 筛选法又称筛法,是求不超过自然数N(N>1)的所有质数的一种方法.据说是古希腊的埃拉托斯特尼(Eratosthenes,约公元前274-194年)发明的,又称埃拉托斯特尼筛子. ...
- Struts2框架05 result标签的类型、拦截器
1 result标签是干什么的 就是结果,服务器处理完返回给浏览器的结果:是一个输出结果数据的组件 2 什么时候需要指定result标签的类型 把要输出的结果数据按照我们指定的数据类型进行处理 3 常 ...
- git在eclipse中的配置 完整版 转载
http://www.cnblogs.com/zhxiaomiao/archive/2013/05/16/3081148.html
- 面试题:struts 值栈 有用
一. 核心部分 1. [核心试题]完成当天课堂练习 2. [多选题] 阅读如下代码中,下列哪种方式可以在页面正确迭代获取集合中的数据 (ABC) public String add(){ ValueS ...