蒟蒻re求条!!!
查看原帖
蒟蒻re求条!!!
1140231
ChangeYuAN楼主2024/8/10 09:11
#include <bits/stdc++.h>
using namespace std;
int T;
stack<char> st;

signed main() {
	scanf("%d", &T);
	for (int i = 1; i <= T; i++) {
		string s;
		scanf("%s", &s);
		bool p = 1;
		for (int j = 0; j < s.size(); j++) {
			int c = char(s[j]);
			if (c == '(' || c == '[') {
				st.push(c);
			}
			if ((c == ')' || c == ']') && !st.empty()) {
				if ((c == ')' && st.top() != '(') || (c == ']' && st.top() != '[')) {
					p = 0;
				} else {
					if (!st.empty())
						st.pop();
					else {
						p = 0;
					}
				}
			}

		}
		if (!st.empty())
			p = 0;
		if (p) {
			printf("Yes");
		} else {
			printf("No");
		}
		puts("");
	}
}
2024/8/10 09:11
加载中...