ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2020-12-21 20:57:47  阅读:215  来源: 互联网

标签:692 based string int characters test Yes include Round


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


标签:692,based,string,int,characters,test,Yes,include,Round
来源: https://blog.csdn.net/qq_45891413/article/details/111499615

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有