Codeforces Round #692 (Div. 2, based on Technocup 2021 Elimination Round 3) A. In-game Chat 模拟

You have been assigned to develop a filter for bad messages in the in-game chat. A message is a string S of length n, consisting of lowercase English letters and characters ‘)’. The message is bad if the number of characters ‘)’ at the end of the string strictly greater than the number of remaining characters. For example, the string “)bc)))” has three parentheses at the end, three remaining characters, and is not considered bad.

Input
The first line contains the number of test cases t (1≤t≤100). Description of the t test cases follows.

The first line of each test case contains an integer n (1≤n≤100). The second line of each test case contains a string S of length n, consisting of lowercase English letters and characters ‘)’.

Output
For each of t test cases, print “Yes” if the string is bad. Otherwise, print “No”.

You can print each letter in any case (upper or lower).

Example
inputCopy
5
2
))
12
gl))hf))))))
9
gege)))))
14
)aa))b))))))))
1
)
outputCopy
Yes
No
Yes
Yes
Yes
题意就可以知道只看最后的括号数去匹配前面的字符

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<assert.h>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
ll a[maxn],b[maxn];
map<string, int>mp;
void solve(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		int n;
		cin>>n;
		string s;
		cin>>s;
		int sum=0;
		for(int i=s.size()-1;i>=0;i--){
    
    
			if(s[i]==')') sum++;
			else break;
		}
		if(sum>s.size()/2){
    
    
			cout<<"Yes"<<endl;
		}
		else{
    
    
			cout<<"No"<<endl;
		}
	}
}
int main()
{
    
    
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	solve();
	return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_45891413/article/details/111499615