习题6-1 平衡的括号(Parentheses Balance, UVa 673)
来源:互联网 发布:男网络歌手好听的歌曲 编辑:程序博客网 时间:2024/05/22 08:11
水题。但还是wa了。。
注意空字符串以及最后匹配完仍有剩余的情况即可。
注意空字符串以及最后匹配完仍有剩余的情况即可。
#include <iostream>#include <string>#include <vector>#include <stack>#include <queue>#include <deque>#include <set>#include <map>#include <algorithm>#include <functional>#include <utility>#include <cstring>#include <cstdio>#include <cstdlib>#include <ctime>#include <cmath>#include <cctype>#define CLEAR(a, b) memset(a, b, sizeof(a))#define IN() freopen("in.txt", "r", stdin)#define OUT() freopen("out.txt", "w", stdout)#define LL long long#define maxn 100005#define maxm 1005#define mod 1000000007#define INF 1000000007#define eps 1e-5#define PI 3.1415926535898#define N 26using namespace std;//-------------------------CHC------------------------------//char in[maxn];map<char, int> bracket;int main() {//IN(); OUT();bracket['('] = 1;bracket[')'] = -1;bracket['['] = 2;bracket[']'] = -2;int T;scanf("%d", &T); getchar();while (T--) {fgets(in, maxn, stdin);stack<char> sta;bool ok = true;for (int i = 0; in[i] != '\n'; ++i) {if (bracket[in[i]] > 0) sta.push(in[i]);else {if (sta.size()) {char cur = sta.top(); sta.pop();if (bracket[cur] + bracket[in[i]]) { ok = false; break; }}else { ok = false; break; }}}if (sta.size()) ok = false;puts(ok ? "Yes" : "No");}}
阅读全文
0 0
- 习题6-1 平衡的括号(Parentheses Balance, UVa 673)
- Uva 673 Parentheses Balance 平衡的括号
- 平衡的括号(Parentheses Balance,UVa 673)
- UVa 673 Parentheses Balance 平衡的括号
- [UVa 673] 平衡的括号(Parentheses Balance)
- UVa OJ Parentheses Balance 673 括号平衡
- Parentheses Balance 平衡的括号 UVA 673 (DFS求解)
- uva 673 Parentheses Balance (平衡的括号)堆栈模拟
- 算法竞赛入门经典 第二版 习题6-1 平衡的括号 Parentheses Balance uva673
- 习题 6-1 平衡的括号 UVa 673
- UVA673:Parentheses Balance(平衡的括号)
- UVA 673 Parentheses Balance(括号匹配)
- UVa 673 Parentheses Balance(括号配对 栈)
- uva 673 Parentheses Balance 习题6-1 (栈——基础练习)
- 习题6-1 平衡的括号 UVa673
- 习题6 -1 Parentheses Balance uva673 简单栈的应用
- 习题6-1 UVa673 Parentheses Balance(栈)
- UVa 673 Parentheses Balance
- 计算机二级易混点
- 表格布局注册页面
- android 关机流程详细分析
- Unsupported major.minor version 51.0
- 高德地图开发Key的申请
- 习题6-1 平衡的括号(Parentheses Balance, UVa 673)
- Eclipse+Maven创建webapp项目<一>
- LinkedBlockingQueue 与PriorityQueue -- JAVA 基础
- 494. Target Sum(M)
- [设计模式]动态代理模式
- (双重循环之)c语言回顾之冒泡排序
- [BZOJ1131][POI2008]Sta(树形dp+维护)
- Color the fence
- 双系统安装 windows10 ubuntu17.04server版本