1 solutions
-
0
C++ :
#include <bits/stdc++.h> using namespace std; string s; //检验是否匹配 bool check(){ stack<char> p;//定义能够存储char的栈 p.push('#');//先存一个#,避免空栈判断 for(int i = 0;i < s.size();i++){ char c = s[i]; if(c == ')'){ if(p.top() != '(') return false; else p.pop(); }else if(c == ']'){ if(p.top() != '[') return false; else p.pop(); }else{ p.push(c); } } return (p.size() == 1); } int main(){ cin>>s; if(check()){ cout<<"yes"<<endl; }else{ cout<<"no"<<endl; } return 0; }
- 1
Information
- ID
- 10482
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By