NYOJ 2 括号配对问题
2015-11-11 21:11
281 查看
#include <string.h> #include <stdio.h> #include <iostream> #include <vector> using namespace std; int main() { int n = 0; cin >> n; while (n--) { char str[10005]; cin >> str; int len = strlen(str); char vec[10005]; int flag = 1; int j=-1; for (int i = 0; i < len; i++) { switch (str[i]) { case '(': case '[': j++; vec[j]=str[i]; break; case ')': case ']': if (j<0)/*处理特殊情况*/ { flag = 0; } else { if (int(vec[j]) == int(str[i]) - 1 || int(vec[j]) == int(str[i]) - 2) { vec[j] = NULL; j--; } else { flag = 0; } } break; default: break; } } if (strlen(vec) != 0) { flag = 0; } if (flag==0) { cout << "No" << endl; } else { cout << "Yes" << endl; } } return 0; }其实思路不难,各种情况要考虑到,想的往下写就OK
相关文章推荐
- 网络路由技术及运用2
- 获取免费的Camtasia Studio 2使用授权
- 选择模式 - XSL教程 - 2
- JS Common 2 之比较常用到的函数第1/3页
- 让Sublime Text 2支持GB2312和GBK编码
- 野人过河问题
- Video 5 Part 2 计算子网
- 诺基亚N8
- Sublime Text 2 快捷键用法大全
- 四个人过桥分别用时1、2、5、10,每次最多两个人过桥,只有一把手电,求时间最短
- 2
- CentOS /usr/libexec/gconf-sanity-check-2 exited with status 256问题解决
- 关于Linux实时性能的研究及测试 2
- init 0-6 (启动级别:init 0,1,2,3,4,5,6)
- programming language
- (2)开始构建:一个基本的应用--ZF2官方教程译文
- iOS cocos2d 2游戏开发实战(第3版)
- 一、struts 2 基础---3.struts.xml的配置
- Struts 2 学习(一) 环境配置
- Sublime text 2 license