uva673 表达式stack
来源:互联网 发布:汽车销售网站源码 编辑:程序博客网 时间:2024/05/23 19:50
#include<stdio.h>#include<iostream>#include<string.h>#include<stack>using namespace std;int main(){<span style="white-space:pre"></span>int n=0;<span style="white-space:pre"></span>cin >> n;<span style="white-space:pre"></span>getchar();<span style="white-space:pre"></span>char str[256];<span style="white-space:pre"></span>while (n--){<span style="white-space:pre"></span>gets_s(str);<span style="white-space:pre"></span>int len = strlen(str);<span style="white-space:pre"></span>stack <char> s;<span style="white-space:pre"></span>char ch;<span style="white-space:pre"></span>bool ok = true;<span style="white-space:pre"></span>for (int i = 0; i < len;i++){<span style="white-space:pre"></span>ch = str[i];<span style="white-space:pre"></span>switch (ch)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>case'(':<span style="white-space:pre"></span>case'[':<span style="white-space:pre"></span>s.push(ch); break;<span style="white-space:pre"></span>case')':<span style="white-space:pre"></span>case']':<span style="white-space:pre"></span>if (s.empty()) ok = false;<span style="white-space:pre"></span>else {<span style="white-space:pre"></span>if (s.top() == '('&&ch != ')' || s.top() == '['&&ch != ']')<span style="white-space:pre"></span>ok = false;<span style="white-space:pre"></span>s.pop();<span style="white-space:pre"></span>}<span style="white-space:pre"></span>break;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>if (s.empty()&&ok)<span style="white-space:pre"></span>cout << "Yes" << endl;<span style="white-space:pre"></span>else cout << "No" << endl;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>return 0;}
0 0
- uva673 表达式stack
- uva673
- uva673
- UVa673
- UVA673括号匹配之vector和stack使用的时候的注意点
- stack 实现中缀表达式
- stack(括号,表达式)
- 【Stack】表达式合法判断
- C++Stack应用-表达式计算器
- Stack-c#堆栈计算表达式
- 利用stack计算后缀表达式
- nyoj--35 表达式求值(stack)
- nyoj1272~表达式求值(stack+模拟)
- uva673 Parentheses Balance
- UVA673-括号平衡
- UVA673 :Parentheses Balance
- UVA673- Parentheses Balance
- 栈的应用uva673
- Base64编码/解码器
- relink处理ORA-12547:TNS:lost contact
- Kali Linux 常见错误整理
- JAVA异常处理机制
- vnc使用复制粘贴
- uva673 表达式stack
- 网易云加密
- Android控制台程序利用GPU处理图像
- ndroid中的MotionEvent 及其它事件处理
- 最大乘数
- SVN--visual svn service安装问题
- 移动安全时代,如何保护你的app
- Objective-C 程序设计 第九章
- C语言基础-指针