萌新妹子求助!!
查看原帖
萌新妹子求助!!
553498
lnscq楼主2023/7/8 07:34
#include<bits/stdc++.h>
using namespace std;
stack<char> s;
int n;
char couple(char p){
	if(p==']'){
		return '[';
	}else if(p=='}'){
		return '{';
	}else{
		return '(';
	}
	return '/0';
} 
int main(){
	cin>>n;
	string p;
	getline(cin,p);
	while(n--){
		while(!s.empty()){
			s.pop();
		}
		getline(cin,p);
		for(int i=0;i<p.size();++i){
			if(s.empty()){
				s.push(p[i]);
				continue;
			}
			if(couple(p[i])==s.top()){
				s.pop();
			}else{
				s.push(p[i]);
			}
		}
		if(s.empty()){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
} 

问题在于只会输出No是怎么回事

2023/7/8 07:34
加载中...