Alternating Current
Codeforces Round #200 (Div. 1) B:http://codeforces.com/problemset/problem/343/B
题意:这一题看懂题意是关键,题目的意思就是两根a,b电线相互缠绕,+表示a在b的上面,-表示b在a的上面,给以一个串,然后问你这两根线能否解开。
题解:显然,如果两个相邻的++或者--的话可以直接消去,然后就会想到用栈来模拟,相同的就消去,不同的就进栈,最后判断栈内是否为空就可以了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+;
char ans[N],a[N];
int n,top;
int main(){
while(~scanf("%s",a)){
n=strlen(a);top=;
for(int i=;i<n;i++){
if(top==){
ans[++top]=a[i];
}
else if(a[i]==ans[top]){
top--;
}
else ans[++top]=a[i];
}
if(top==)printf("Yes\n");
else
printf("No\n");
}
}
Alternating Current的更多相关文章
- Codeforces Round #200 (Div. 1) B. Alternating Current 栈
B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- CodeForces - 344D Alternating Current (模拟题)
id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" ...
- Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)
D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...
- cf D. Alternating Current
http://codeforces.com/contest/344/problem/D #include <cstdio> #include <cstring> #includ ...
- Codeforces 344D Alternating Current 简单使用栈
Description Mad scientist Mike has just finished constructing a new device to search for extraterres ...
- [CodeForces 344D Alternating Current]栈
题意:两根导线绕在一起,问能不能拉成两条平行线,只能向两端拉不能绕 思路:从左至右,对+-号分别进行配对,遇到连续的两个“+”或连续的两个“-”即可消掉,最后如果全部能消掉则能拉成平行线.拿两根线绕一 ...
- Electronic oscillator
https://en.wikipedia.org/wiki/Electronic_oscillator An electronic oscillator is an electronic circui ...
- Arduino 极速入门系列 - 光控灯(1)- 关于理论和 LED 那些事
点个 LED 闪亮好像太单调,这次来个光控 LED 灯.这个其实不需要 Arduino 也能做,这次只是用来演示一下 PWM 在 Arduino 里面的做法.PWM 原理后面会解释.这次用充电宝提供 ...
- RFID 基础/分类/编码/调制/传输
不同频段的RFID产品会有不同的特性,本文详细介绍了无源的感应器在不同工作频率产品的特性以及主要的应用. 目前定义RFID产品的工作频率有低频.高频和甚高频的频率范围内的符合不同标准的不同的产品,而且 ...
随机推荐
- android 66 sharedperference的使用
package com.itheima.qqlogin; import java.io.BufferedReader; import java.io.File; import java.io.File ...
- 深度剖析:CDN内容分发网络技术原理--转载
1.前言 Internet的高速发展,给人们的工作和生活带来了极大的便利,对Internet的服务品质和访问速度要求越来越高,虽然带宽不断增加,用户数量也在不断增加,受Web服务器的负荷和传输距离等因 ...
- PureMVC(JS版)源码解析(四):Notifier类
上一篇博客中,我们解析了Observer(观察者)类,这一篇博客我们来讲Notifier(通知着)类.关于Notifier类,源码注释上有这么一段: * @class puremvc.Not ...
- (亲测)设置myeclipse打开默认工作空间
亲测一: 1.找到D:\MyEclipse 8.5\configuration\ config.ini 这个文件 2.找到这一行instance.area.default 3.将后面的地址替换为你想要 ...
- WPF自定义窗体仿新毒霸关闭特效(只能在自定义窗体中正常使用)
比较简单的一个小功能,和新毒霸类似的效果. 效果代码: bool closeStoryBoardCompleted = false; DoubleAnimation closeAnimation1; ...
- C++ 读取XML文件(tinyXML库的应用)
C++读取xml有很多第三方的xml解析库,最近使用tinyxml库来解析,下面直接上应用例子: Skin.xml文档内容如下: <UI> <Image name="ban ...
- Bash中的数组
变量:$VAR或者${VAR} 数组:${VAR[$i]} 打印整个数组:echo ${VAR[@]} 统计数组元素个数:echo ${#VAR[@]} 从文件读入数组(按行读入):VAR=(`cat ...
- Singleton设计模式 分类: 设计模式 2014-12-03 17:54 59人阅读 评论(0) 收藏
实现方法: public class SingleTon<T> where T : class, new() { protected SingleTon() { } pri ...
- sqlserver 自定义字符串分割函数.
--SQL Server Split函数 --Author: sq --说明:被分割后的字段为:short_str --支持分割符多字节 --使用方法 --Select * FROM splits(' ...
- Ubuntu12.04中安装ns-allinone-2.34
1.首先安装ns2所需的组件.库之类: $sudo apt-get update $sudo apt-get install build-essential $ tcl8.-dev tk8. tk8. ...