竞赛
考级
#include<bits/stdc++.h> using namespace std; int main(){ stack<char> st; char n; int i=0,flag=1; while(cin>>n){ if(n=='('){ st.push(n); } else if(n==')'){ if(!st.empty()){ st.pop(); } else{ flag=0; } } i++; } if(!st.empty()){ flag=0; } if(flag){ cout<<"YES"; } else{ cout<<"NO"; } return 0; }
法西斯玫瑰
#include<iostream> #include<queue> using namespace std; queue<char> q; int main(){ string a; cin >> a; int al = a.size(); for(int i = 0;i < al;i++){ if(a[i] == '(') q.push(a[i]); if(a[i] == ')' && q.size() == 0){ cout << "NO"; return 0; } if(a[i] == ')') q.pop(); }
DARK SPECTRE
因为今天上课的时候讲到了stack 所以就诞生了这一发数组模拟解法的题解(数组版栈) 而且我妈告诉我这题要用数组模拟做 话不多说,上代码 看着dalao们都用着stack 突然感觉我hx(好虚)啊 内心os:明明可以用数组模拟为什么要用栈(小声) 洛谷原题
范特东
#include<iostream> #include<stack> using namespace std; stack<char> s; string q; int main(){ cin>>q; for(int i=0;q[i]!='@';i++){ if(q[i]'('){ s.push('('); } else if(q[i]')') { if(s.empty()){ cout<<"NO"; return 0; } else { s.pop(); } } } if(s.empty()) cout<<"YES"; else cout<<"NO"; return 0; }
XBY
陈炜涵
张高纶
#include<bits/stdc++.h> using namespace std; queue<char> q; int main(){ string a; cin >> a; for(int i = 0;i < a.size();i++){ if(a[i] == '(') q.push(a[i]); if(a[i] == ')' && q.size() == 0){ cout << "NO"; return 0; }else if(a[i] == ')') q.pop(); } if(q.size() == 0) cout << "YES"; else cout << "NO"; return 0; }
准
Creeper
majmDZB
余承轩
#include<bits/stdc++.h> using namespace std; int main(){ stack <char> st; string s; cin >> s; for (int i = 0; i < s.size(); i++){ if (s[i] == '(') st.push(s[i]); else if (s[i] == ')'){ if (st.size()) st.pop(); else{ cout << "NO"; return 0; } } } if (st.size()) cout << "NO"; else cout << "YES"; }
Green_wang.ntr
̖̗̘̙̐̑̒̓̔̕(闫子路)
#include <bits/stdc++.h> using namespace std; stack<char> st; int main(){ char c; while(cin >> c){ if(c == '@') break; if(c == '(') st.push('('); else if(c == ')') { if(st.size() == 0){ cout << "NO"; return 0; }else{ st.pop(); } } } string a = st.empty() ? "YES" : "NO"; cout << a; return 0; }
凹凸
AX6t5
回来看看
Phoebe
共37条