UVA - 673 - Parentheses Balance
来源:互联网 发布:金扎医疗器械软件 编辑:程序博客网 时间:2024/05/21 09:24
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_problem&problem=614
题意:
输入括号字符串,判断是否匹配正常。常用于文本编辑系统里。
解题:
水题,用栈边保存边出栈。
#include <iostream>#include <string>#include <stack>#include <stdio.h>using namespace std;// #define LOCAL_TESTbool Check(string str){stack<char> sTemp;bool bCorrect = true;for ( int index=0; index<str.length(); index++ ){switch ( str[index] ){case '(':case '[':sTemp.push(str[index]);break;case ')':if ( sTemp.empty() || sTemp.top() != '(' )return false;elsesTemp.pop();break;case ']':if ( sTemp.empty() || sTemp.top() != '[' )return false;elsesTemp.pop();break;}} // end forif ( !sTemp.empty() )return false;return true;}int main(){#ifdef LOCAL_TESTfreopen("f:\\in.txt", "r", stdin);freopen("f:\\out.txt", "w+", stdout);#endifint nCase;cin >>nCase;cin.ignore();while ( nCase-- ){string str;// cin >>str;// 以空格为区分符,行里有空格咋办。。。太挫了!getline(cin, str);bool bRes = Check(str);if ( bRes )cout <<"Yes" <<'\n';elsecout <<"No" <<'\n';} // end whilereturn 0;}
0 0
- UVa 673 Parentheses Balance
- uva 673 - Parentheses Balance
- Uva 673 Parentheses Balance
- uva 673 - Parentheses Balance
- UVa 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- UVA 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- UVA 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- Uva-673-Parentheses Balance
- UVa 673 - Parentheses Balance
- uva 673Parentheses Balance
- uva-673 Parentheses Balance
- UVA 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- uva 673 - Parentheses Balance
- uva 673 Parentheses Balance
- Schema specified is not valid. Errors:
- [Network]Network Layer
- Eagle 画板-拼板-输出Gerber到SeeedStudio打样过程笔记
- JAVA面试题解惑系列(七)——日期和时间的处理
- STM32外部中断详解
- UVA - 673 - Parentheses Balance
- ubuntu关闭iptables
- java MD5
- 学习不能急于求成
- shark on yarn udf的使用
- UVA 11020 - Efficient Solutions
- JAVA面试题解惑系列(八)——聊聊基本类型(内置类型)
- 用文件保存的学生名单
- The Swift Programming Language手册下载