1 solutions
-
0
C++ :
#include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <cstring> #include <set> #include <map> #include <stack> using namespace std; stack<char>st; char p[6]={'{','}','[',']','(',')'}; bool in(char c){ for(int i=0;i<6;i++) if(p[i]==c) return true; return false; } int main(){ string s; while(cin>>s){ while(!st.empty()) st.pop(); for(int i=0;i<s.size();i++){ if(in(s[i])){ if(!st.empty()){ if(st.top()=='[' && s[i]==']') st.pop(); else if(st.top()=='{' && s[i]=='}') st.pop(); else if(st.top()=='(' && s[i]==')') st.pop(); else st.push(s[i]); } else st.push(s[i]); } } if(st.empty()) printf("True\n"); else printf("False\n"); } return 0; }
- 1
Information
- ID
- 16524
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By