[codeforces 1305B] Kuroni and Simple Strings 有点象快排

Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated, T-shirts + prizes!)   比赛人数7420

[codeforces 1305B] Kuroni and Simple Strings   有点象快排

总目录详见https://blog.csdn.net/mrcrack/article/details/103564004

在线测评地址https://codeforces.ml/contest/1305/problem/B

ProblemLangVerdictTimeMemory
B - Kuroni and Simple Strings GNU C++11Accepted31 ms0 KB

看看代码挺简单,但是看着题目,将代码编写出来,就不简单。

delete these bold characters from the string and to get '))()'.若能接着这句再继续说,还需进行一次操作,删除(),才能得到Kuroni想要的字串)),那该有多好。

()() are not simple.若能说明,()()不是Kuroni想要的字串,那该有多好。

Input:

(()())

Output:

1
4
1 2 5 6 

还有一种删法

1

6

1 2 3 4 5 6

该题,就容易上手了。

意见,陌生度大的题,就要做更详细的说明。

AC代码如下

#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 1010
using namespace std;
int ans[maxn],tot;
char s[maxn];
int main(){
	int l,r,len,i;
	scanf("%s",s+1);
	len=strlen(s+1);
	l=1,r=len;
	while(1){
		while(l<=len&&s[l]==')')l++;
		while(1<=r&&s[r]=='(')r--;
		if(l>r)break;//绝不可能出现l==r的情况。
		ans[++tot]=l,ans[++tot]=r;
		l++,r--;
	}
	if(!tot)printf("0\n");
	else{
		printf("1\n");
		printf("%d\n",tot);
		sort(ans+1,ans+1+tot);
		for(i=1;i<tot;i++)printf("%d ",ans[i]);
		printf("%d\n",ans[tot]);
	}
	return 0;
}

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值