文章
2
粉丝
65
获赞
2
访问
1.3k
//
// Created by Beyong on 2024/1/18.
//
#include<iostream>
#include<stack>
using namespace std;
int char_weight(char s);
int main() {
int n = 5;
cin >> n;
cin.ignore();
while (n) {
string str;
bool flag = true;
getline(cin, str);
stack<char> stack1;
int number = 0;
for(char ix : str) {
if(ix == '{' || ix == '[' || ix == '(' || ix == '<') {
stack1.push(ix);
number = 0;
} else {
if(!stack1.empty()) {
char temp_char = stack1.top();
stack1.pop();
if(char_weight(temp_char) != char_weight(ix)) {
flag = false;
break;
}
if(char_weight(ix) < number) {
flag = false;
break;
}
number = char_weight(ix);
} else {
flag = false;
break;
}
}
}
if(!stack1.empty()) {
flag = false;
}
if(flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
n--;
}
return 0;
}
int char_weight(char s) {
switch(s){
case '{':
case '}&...
登录后发布评论
暂无评论,来抢沙发