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所示 ...
随机推荐
- 使用/dev/dsp的wav文件播放器源码
转载于:http://blog.csdn.net/dux003/article/details/5459423 #include #include #include #include #include ...
- contentvalue的探究(结构,用途)
contentvalue类似HASHMAP,但是KEY只能为STRING 该类用于数据库操作时对数据的封装,可以避免使用SQL语句,为后期创建CONTENTPROVIDER提供便利. 如果没有上述需求 ...
- java的邮件系统实现
想要java中邮件发送和接收邮件,首先需要支持SMTP- pop/pop3/IMAP协议,发送的话还需要配置文件,来对程序提供相应的接口,只需要这两个文件,就可以实现邮件的接收发送, 协议为jar包封 ...
- C语言-郝斌笔记-006排序及查找
1. int partion(int *a, int low, int high) { int value = a[low]; int t; while (low < high) { while ...
- etl 获取列数据类型
QueryInfo info = new QueryInfo(); info.CustomSQL = @" select column_name, data_type, data_preci ...
- python中list的使用
1.list(列表)是一种有序的集合,可以随时添加.修改.删除其中的元素. 举例:listClassName = ['Jack','Tom','Mark'] 列表可以根据索引获取元素,如:listCl ...
- SDUT 3399 数据结构实验之排序二:交换排序
数据结构实验之排序二:交换排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 冒泡排序和快 ...
- 格式化字符串攻击原理及示例.RP
格式化字符串攻击原理及示例 一.类printf函数簇实现原理 类printf函数的最大的特点就是,在函数定义的时候无法知道函数实参的数目和类型. 对于这种情况,可以使用省略号指定参数表. 带有省略号的 ...
- 监控linux系统的简易脚本
我先把脚本粘贴在这吧,方便大家观看,其中也是借鉴了不少其他大神的东西,这个脚本主要是用来监控服务器.用户.日志,还得创建备份,等等等等.最近学的shell比较多,就用这个来练练手了,比较简单,大家凑合 ...
- C++笔记--指针数组和结构
指针 类型为T*的变量能保存一个类型T对象的地址 Char c=‘a’:Char * p=& c://保存了c的地址 指针的操作一般都是间接的引用,就是相当于引用指针所指的对象. 0是一个特殊 ...