欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVa673

程序员文章站 2024-03-19 09:29:52
...
#include <stack>
#include <string>
#include <iostream>
using namespace std;

int main() {
	int T;
	cin >> T;
	getchar();
	while(T--) {
		string s;
		getline(cin, s);
		stack<char> st;
		bool flag = true;
		for(int i = 0; i < s.size(); i++) {
			if(s[i] == '(' || s[i] == '[')
				st.push(s[i]);
			else if(!st.empty() && s[i] == ')' && st.top() == '(')
				st.pop();
			else if(!st.empty() && s[i] == ']' && st.top() == '[')
				st.pop();
			else
				flag = false;
		}
		if(flag && st.empty())
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}