标签:style push splay val har mes lse controls one
#include <iostream> #include <string> #include <stack> using namespace std; bool isValid(string s) { stack<char> a; int len=s.size(); if(len==1) return 0; if(len==0) return 1; for(int i=0;i<len;i++) { switch (s[i]) { case ‘)‘: { if((a.size()!=0)&&a.top()==‘(‘) a.pop(); else return false; break; } case ‘}‘: { if((a.size()!=0)&&a.top()==‘{‘) a.pop(); else return false; break; } case ‘]‘: { if((a.size()!=0)&&a.top()==‘[‘) a.pop(); else return false; break; } default:a.push(s[i]); break; } } cout<<a.size()<<endl; if(a.size()==0) return true; else return false; } int main() { string s="){"; std::cout << isValid(s) << std::endl; return 0; }
标签:style push splay val har mes lse controls one
原文地址:https://www.cnblogs.com/biat/p/10525081.html