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

你需要设计一个游戏内聊天的不良消息过滤器。如果字符串末尾的')'字符数量严格大于其余字符数,则认为该消息是不良的。例如,字符串")bc)))"不被认为是不良的。输入包含测试用例数和每个用例的字符串,输出对应是否为不良消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值