题意:

检测括号是否匹配,注意有空格

#include<stdio.h>
#include<iostream>
#include <strstream>
#include<string>
#include<memory.h>
#include<math.h>
#include<sstream>
#include<queue>
#include<stack>
using namespace std;
struct Node
{
int r;
int c;
int total;
};
const Node dir[] = { { -1, 2 }, { 1, 2 }, { -2, 1 }, { 2, 1 }, { -2, -1 }, { 2,
-1 }, { -1, -2 }, { 1, -2 } }; int main()
{ string yes = "Yes";
string no = "No";
int n;
cin >> n;
string str;
getline(cin, str);
while (n--)
{
getline(cin, str); int length = str.length();
stack<char> s;
int ok = 1;
for (int i = 0; i < length; i++)
{
char c = str.at(i);
if (c == ' ')
continue;
if (c == '(' || c == '[')
{
s.push(c);
}
else if (c == ')' || c == ']')
{
if (s.size() == 0)
{
ok = 0;
break;
}
else
{
char cc = s.top();
s.pop();
if (c == ')')
{
if (cc != '(')
{
ok = 0;
break;
}
}
else
{
if (cc != '[')
{
ok = 0;
break;
}
}
}
}
}
if (s.size() != 0)
ok = 0; if (ok)
cout << yes << endl;
else
cout << no << endl;
}
}

  

最新文章

  1. 快速入门系列--WCF--08扩展与新特性
  2. javascript去掉空格
  3. 1069 Nim游戏
  4. Java——交通灯
  5. mysql特有语法
  6. JFrame 实现全屏透明背景
  7. 写自己的WPF样式 - 窗体
  8. nginx自定义模块编写-根据post参数路由到不同服务器
  9. meminfo,df,
  10. 百度api集合!
  11. NSIS 设置系统变量
  12. 浏览器各个版本和系统(chrome/safari/edge/qq/360)
  13. BZOJ1688|二进制枚举子集| 状态压缩DP
  14. Javascript - ExtJs - 常用方法和属性
  15. Give root password for maintenance(or type control -D to continue)
  16. delimiters 插值 选项
  17. Mybatis 系列2-配置文件
  18. Charles抓包https
  19. 基于Java的简易表达式解析工具(一)
  20. 第十一章 自己实现一致性hash算法

热门文章

  1. 8个iPhone防盗秘籍 为手机和资料安全保驾护航
  2. CF1093:E. Intersection of Permutations(树状数组套主席树)
  3. POJ 3069:Saruman's Army
  4. Tempter of the Bone dfs+剪枝
  5. 《DSP using MATLAB》Problem 4.1
  6. python 命名空间和作用域
  7. 系列文章--jQuery教程
  8. Servlet容器请求处理
  9. bzoj1830 Y形项链
  10. java中使HttpDelete可以发送body信息