括号匹配问题
2016-03-25 21:33
302 查看
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=2
#include <stdio.h> #include <stack> #include <map> #include <queue> #include <math.h> #include <stdlib.h> #include <vector> #include <algorithm> #include <iostream> #include <string> using namespace std; string s; int main() { int t; scanf("%d",&t); while(t--) { stack<char> ans;///模拟进出站 int i; cin>>s; for(i=0; i<s.size(); i++) { if(s[i]=='['||s[i]=='(') ans.push(s[i]); else if(ans.size()) { if(s[i]==')'&&ans.top()=='('||s[i]==']'&&ans.top()=='[') { ans.pop(); } else { break; } } else break; } if(i==s.size()&&ans.empty()) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- POJ1679
- sin的泰勒展开
- IOS开发-OC学习-MD5加密
- poj 1962(并查集+带权更新)
- 游戏中有多个摄像机时,注意摄像机对游戏物体位置的影响
- 码农小汪-struts2学习5-表单的验证的两种方法
- ExtJs TabPanel右键功能插件Ext.ux.TabCloseMenu
- c++复习要点总结之七——运算符重载
- 陀螺仪+wifi从机
- 用含成员函数的类来实现输入和输出时间
- 使用Unidac内置连接池
- Java——URL和URLConnection
- Nyoj 虚拟的城市之旅(bfs)
- [android] activity的生命周期
- numpy 常用api(四)
- struts2图片上传
- 平滑空间滤波器
- Leetcode 116. Populating Next Right Pointers in Each Node
- 【数据结构】二叉树结点插入和前序、中序、后序遍历的递归实现
- Java中的字符串常量池