- C++
1355:字符串匹配问题(strs)【寻找错误】
- 2024-2-17 17:47:23 @
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
string a;
int stk[1000],b[1000],top=0;
int main(){
int n;
stk[0]=5;
cin>>n;
for(int i=0;i<n;i++){
cin>>a;
for(int j=0;j<a.size();j++){
if(a[i]=='<')b[j+1]=1;
if(a[i]=='(')b[j+1]=2;
if(a[i]=='[')b[j+1]=3;
if(a[i]=='{')b[j+1]=4;
if(a[i]=='}')b[j+1]=5;
if(a[i]==']')b[j+1]=6;
if(a[i]==')')b[j+1]=7;
if(a[i]=='>')b[j+1]=8;
}
top=0;
int flog=1;
for(int j=1;j<=a.size();j++){
if(b[j]<=4){
stk[++top]=b[j];
if(stk[top]>stk[top-1]){
flog=0;
break;
}
}else{
if(stk[top]+b[j]==9){
top--;
}else{
flog=0;
break;
}
}
}
if(flog==1&&top==0)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
0 条评论
目前还没有评论...