Kuroni and Simple Strings

Posted 诸葛阵御

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kuroni and Simple Strings相关的知识,希望对你有一定的参考价值。

题目



#include <iostream>
#include <algorithm>
using namespace std;
int main() 
	string s;
	cin>>s;
	int len=s.length();
	int ans=0;
	int arr[len+3]=0;	//记录下标 
	int l=0; 
	int r=len-1;
	while (l<r) 
		while (l<len&&s[l]==')') 	//从第一个(开始 
			l++;
		
		while (r>=0&&s[r]=='(') 	//从最后一个)开始 
			r--;
		
		if (s[l]=='('&&s[r]==')'&&l<r) 	//若为简单字符串 
			ans+=2;
			arr[l+1]=l+1;
			arr[r+1]=r+1;
			l++;
			r--;
			
	
	sort(arr+1,arr+len+1);
	if (ans==0) 	
			cout<<'0';
	 else 
		cout<<'1'<<"\\n";
		cout<<ans<<"\\n";
		int t=1;
		while (arr[t]==0) 	//去0 
			t++;
		
		for (int i=t;i<ans+t;i++) 
			cout<<arr[i];
			if (i!=ans+t) 
				cout<<' ';
			
		
	
	return 0;

以上是关于Kuroni and Simple Strings的主要内容,如果未能解决你的问题,请参考以下文章