NYoj+stack使用++runtime error概念基础知识不牢细节出错
2015-10-10 17:17
225 查看
点击打开链接
#include<stdio.h> #include<stdlib.h> #include<iostream> #include<string.h> #include<string> #include<cstring> #include<algorithm> #include<stack> using namespace std; int main() { int N=0,i=0; string str; stack<char>s; scanf("%d",&N); while(N--) { cin>>str; int len=str.length(); for(i=0;i<len;i++) { if(str[i]=='['||str[i]=='(') { s.push(str[i]); } else if(str[i]==']') { if(!s.empty()&&s.top()=='[')///一定要先用empty然后才能用top啊 { s.pop(); } else { printf("No\n"); break; } } else if(str[i]==')') { if(!s.empty()&&s.top()=='(')///一定要有先判断是不是empty,才能用top啊 { s.pop(); } else { printf("No\n"); break; } } } if(i==len&&s.empty()) { printf("Yes\n"); } else if(i==len&&!s.empty()) { printf("No\n"); } while(!s.empty()) s.pop();///一定要清空啊 } return 0; }
相关文章推荐
- 《Learning From Data》读书笔记——引言
- java 时间字符串 比较先后
- android弹出对话框
- Eclipse SVN的相关说明及其快捷键 10个最有用的快捷键
- 线段树(1)----- 简单问题 hdu4553
- Linux系统调用和库函数调用的区别
- Redis发布订阅实现原理
- require
- UIImage
- windows 7 下如何搭建FTP服务器
- 关于Ajax跨域访问问题的一种解决办法
- 禁止表情输入
- Java开发前奏
- Linux 文件操作总结
- 内存溢出解决方案(2)
- Ensemble(Cache)通过ODBC连接Mysql数据库并调用其存储过程
- POJ 2777 Count Color(段树)
- 多线程
- 通知NSNotificationCenter
- 简单的在Servlet中弹出对话框,确定后返回