一直RE,求助
查看原帖
一直RE,求助
718169
__int127楼主2023/7/20 22:51
#include <bits/stdc++.h>
using namespace std;
int n;
stack <char> s;
char d;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	s.push('!');
	getchar();
	for (int i = 1; i <= n; i++){
		string tmp;
		getline(cin, tmp);
		int len = tmp.size();
		for (int j = 0; j < len; j++){
			s.push(tmp[j]);
			if (s.top() == ')'){
				if (d == '('){
					s.pop();
					s.pop();
				}
			} else if (s.top() == ']'){
				if (d == '['){
					s.pop();
					s.pop();
				}
			}
			d = s.top();
		}
		if (s.top() == '!'){
			cout << "Yes\n";
		} else {
			cout << "No\n";
			while (!(s.top() == '!')){
				s.pop();
			}
		}
	}
	return 0;
}
2023/7/20 22:51
加载中...