AcWing 3693. 括号匹配
原题链接
简单
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 1e6+10;
int t,n,m,k,l,r,op,x,y;
int f[N];
bool flag;
char ch;
unordered_map<char,char>mp;
void solve(){
mp.emplace('>','<');
mp.emplace(')','(');
mp.emplace('}','{');
mp.emplace(']','[');
stack<char> stk;
while(cin>>ch){
if(ch=='<'||ch=='('||ch=='{'||ch=='['){
stk.push(ch);
}else{
if(stk.empty()){
cout<<"no";
return ;
}
x = stk.top();stk.pop();
if(mp[ch]!=x){
cout<<"no";
return;
}
}
}
if(!stk.empty()){
cout<<"no";
return;
}
cout<<"yes";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}