You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.4 KiB

#include<bits/stdc++.h>
// Õ»
struct Stack {
int s[100];
int top;
} stack;
int main(void) {
char left_d = '{';
char left_z = '[';
char left_x = '(';
char right_d = '}';
char right_z = ']';
char right_x = ')';
int flag = 1;
int have_other_word = 0;
int i;
// ¶ÓÁÐ
char que[100];
int head = 0;
int tail = 0;
stack.top = 0;
gets(que);
tail = strlen(que);
for (i = 0; i < tail; i++) {
if (
que[i] != left_d &&
que[i] != left_z &&
que[i] != left_x &&
que[i] != right_d &&
que[i] != right_z &&
que[i] != right_x
) {
have_other_word = 1;
break;
}
}
if (have_other_word == 0) {
while (head < tail) {
if (que[head] == left_d || que[head] == left_z || que[head] == left_x) {
stack.s[stack.top] = head;
stack.top++;
} else {
if (que[head] == right_d) {
if (que[stack.s[stack.top - 1]] == left_d) {
stack.top--;
} else {
flag = 0;
}
}
if (que[head] == right_z) {
if (que[stack.s[stack.top - 1]] == left_z) {
stack.top--;
} else {
flag = 0;
}
}
if (que[head] == right_x) {
if (que[stack.s[stack.top - 1]] == left_x) {
stack.top--;
} else {
flag = 0;
}
}
}
if (flag == 0) {
break;
}
head++;
}
} else {
flag = 0;
}
if (flag) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}