标签:
3
[(])
(])
([[]()])
No
No
Yes
1 #include <iostream> 2 #include <stack> 3 #include <cstdio> 4 #include <algorithm> 5 #include <cstring> 6 using namespace std; 7 8 9 int main(){ 10 int n; 11 char c; 12 //stack<char> s;//ÔÚÕâÀﶨÒåÕ»£¬ÔòÔÚÏÂÃæÿ´Î½øÐÐÒ»´Î×Ö·û´®Æ¥Å䣬¶¼ÐèÒªÇå¿ÕÕ» 13 cin >> n; 14 getchar(); 15 while(n--){ 16 stack<char> s;//ÔÚÕâÀﶨÒåÕ»Ï൱ÓÚÇå¿ÕÉÏÒ»¸ö×Ö·û´®Óõ½µÄÕ» 17 while(scanf("%c", &c) && (c != ‘\n‘)){ 18 if(s.empty()){ 19 s.push(c); 20 }else{ 21 if((s.top() == ‘[‘ && c == ‘]‘) || (s.top() == ‘(‘ && c == ‘)‘))//‘[‘ºÍ‘]‘,‘(‘ºÍ‘)‘acsiiÂë Ïà²î1 22 s.pop(); 23 else 24 s.push(c); 25 } 26 27 } 28 if(s.empty()) 29 cout << "Yes" << endl; 30 else 31 cout << "No" << endl; 32 //while(!s.empty()){ 33 // s.pop(); 34 //} 35 } 36 37 return 0; 38 }
标签:
原文地址:http://www.cnblogs.com/qinduanyinghua/p/5699259.html