C. Smallest Word

链接

[http://codeforces.com/contest/1043/problem/C]

题意

给你一个只包含a,b的字符串,有一种操作把第1个字符到第i个字符的子串进行反转,问要使最后字符串字典序最小那些位置需要反转,

分析

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	int i,a[1010];
	//freopen("in.txt","r",stdin);
	while(cin>>s){
		memset(a,0,sizeof(a));
		bool flag=1;
		int h=0;
		for(i=0;i<s.length();i++)
		{
			if(s[i]=='a'&&flag&&s[i+1]!='a'){
				a[i]=1;
				flag=0;
			}
			if(s[i]=='a'&&!flag){
			  if(s[i-1]!='a')	a[i-1]=1;
			  if(i==s.length()-1||s[i+1]=='b')	a[i]=1;
			}
		}
		
		for(i=0;i<s.length();i++)
		cout<<a[i]<<' ';
        cout<<endl;
	}
	return 0;
}
posted @ 2018-10-29 21:51  ChunhaoMo  阅读(267)  评论(0)    收藏  举报