【Luogu1739】表达式括号匹配

xiaoxiao2021-02-28  48

problem

solution

codes

#include<iostream> #include<stack> #include<string> using namespace std; int main(){ stack<char>s; string str; cin>>str; bool flag = 1; for(int i = 0; i < str.size(); i++){ if(str[i] == '(')s.push('('); else if(str[i] == ')' && !s.empty())s.pop(); else if(str[i] == ')' && s.empty()){ flag = 0; break; } } if(s.empty() && flag)cout<<"YES\n";//md答案写反了 else cout<<"NO\n"; return 0; }
转载请注明原文地址: https://www.6miu.com/read-2612375.html

最新回复(0)