UVA673 水,模拟栈
来源:互联网 发布:查看linux版本 编辑:程序博客网 时间:2024/05/02 00:07
0)
注意,对于%c的输入,用的scanf。如果cin>> ,char 有坑。
1)
#include <iostream>#include <string.h>#include <stack>#include <stdio.h>using namespace std;int main(){ int kase; cin>>kase; char temp=getchar(); while(kase--){ stack <char> ss; char ch; while(1){ scanf("%c",&ch);//如果是cin,就不会退出 if(ch=='\n'){ break; } if(ss.empty()){ ss.push(ch); continue; } char cur=ss.top(); if(ch==')'&&cur=='('){ ss.pop(); } else if(ch==']'&&cur=='['){ ss.pop(); } else{ ss.push(ch); } } if(ss.empty()){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } while(!ss.empty()){ ss.pop(); } } return 0;}
2)
Description
You are given a string consisting of parentheses () and []. A string of this type is said to be correct:
- (a)
- if it is the empty string
- (b)
- if A and B are correct, AB is correct,
- (c)
- if A is correct, (A) and [A] is correct.
Write a program that takes a sequence of strings of this type and check their correctness. Your program can assume that the maximum string length is 128.
Input
The file contains a positive integer n and a sequence of n strings of parentheses () and [], one string a line.
Output
A sequence of Yes or No on the output file.
Sample Input
3([])(([()])))([()[]()])()
Sample Output
YesNoYes
0 0
- UVA673 水,模拟栈
- uva673 Parentheses Balance(模拟+栈)
- 栈的应用uva673
- uva673 栈 括号匹配
- uva673 - Parentheses Balance(栈)
- UVa673(数据结构 栈)
- uva673
- uva673
- UVa673
- Uva673 Parentheses Balance(栈)
- STL栈的应用—UVA673
- 突然发现有点问题uva673(栈括号匹…
- uva673-栈-(字符读取和清空缓冲区)
- 习题6-1 UVa673 Parentheses Balance(栈)
- 习题6 -1 Parentheses Balance uva673 简单栈的应用
- uva673 Parentheses Balance
- UVA673-括号平衡
- UVA673 :Parentheses Balance
- Matlab给系统自动生成的窗体Figure1改名称
- qt creator : error: Exception at 0x772e93d0, code: 0xc0000409: , flags=0x1 (execution cannot be c
- POJ 3481 set水过
- opencv2实现形态学骨架提取
- 链式编程学习(二)
- UVA673 水,模拟栈
- Spark学习系列——在虚拟机上搭建 Spark 集群的两种方法
- 对oop一些的基本操作
- iOS-实战项目笔记总结-打包错误及解决
- restful是什么
- java笔记day22—GUI(1)
- Git使用总结(包含Git Bash和Git GUI的使用)
- trick-交换数字
- 快速设置Mysql的auto_increment参数