codeforces1276AAs Simple as One and Two

Posted xuanmaiboy

tags:

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

C.As Simple as One and Two

A. As Simple as One and Two
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a non-empty string s=s1s2sns=s1s2…sn, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string ss if there is an integer jj (1jn21≤j≤n−2), that sjsj+1sj+2=sjsj+1sj+2="one" or sjsj+1sj+2=sjsj+1sj+2="two".

For example:

  • Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
  • Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").

Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.

For example, if the string looks like s=s="onetwone", then if Polycarp selects two indices 33 and 66, then "onetwone" will be selected and the result is "ontwne".

What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?

Input

The first line of the input contains an integer tt (1t1041≤t≤104) — the number of test cases in the input. Next, the test cases are given.

Each test case consists of one non-empty string ss. Its length does not exceed 1.51051.5⋅105. The string ss consists only of lowercase Latin letters.

It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.51061.5⋅106.

Output

Print an answer for each test case in the input in order of their appearance.

The first line of each answer should contain rr (0r|s|0≤r≤|s|) — the required minimum number of positions to be removed, where |s||s| is the length of the given line. The second line of each answer should contain rr different integers — the indices themselves for removal in any order. Indices are numbered from left to right from 11 to the length of the string. If r=0r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.

Examples

4
onetwone
testme
oneoneone
twotwo

output

2
6 3
0

3
4 1 7 
2
1 4

  题意:就是给你一串字符串。让你去掉最少的字符,这个字符串不能有连续的“one”,"two"出现,并且保证输入的都是小写字母。输出去掉的最小的字符个数和输出去掉字符的位置(索引从1开始)。

题解:我们删除一个字符后它后面的字符就会补上来,可能再次形成不合法,比如字符串twooo你删除第三个那么后面的又是o,不能这样,我们要选择删除第二个w,而不是two的第三个o.

我们可以分成三种情况:

1.“……one……”我们删除第二个n

2.“……two……”我们删除第二个w

3."……twone……"我们删除第三个o

其实2,3是一种情况,当我们遇到two要判断一下是第二还是第三种情况。

AC代码:

#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
char a[200005];
int main(void)
{
	int t;
	scanf("%d",&t);
	vector<int> v;
	while(t--)
	{
		int top=0;
		v.clear();
		scanf("%s",a);
		int n=strlen(a);
		for(int i=1;i<n-1;i++){
			if(a[i-1]==‘o‘&&a[i]==‘n‘&&a[i+1]==‘e‘)
			{
				a[i]=‘X‘;//记得修改 
				v.push_back(i+1);
			}
			if(a[i-1]==‘t‘&&a[i]==‘w‘&&a[i+1]==‘o‘)
			{
				if(a[i-1]==‘t‘&&a[i]==‘w‘&&a[i+1]==‘o‘&&a[i+2]==‘n‘&&a[i+3]==‘e‘&&i+3<n)
				v.push_back(i+1+1),a[i+1]=‘X‘;
				else
				v.push_back(i+1);a[i]=‘X‘;//记得修改 
			}
		}
		printf("%d
",v.size());
		for(vector<int>::iterator it=v.begin() ;it!=v.end() ;it++ )
		printf("%d ",*it);
		printf("
");
	}
	return 0;
}

  

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

CodeForces - 665C Simple Strings (水题)

CodeForces - 11D A Simple Task

codeforces 626E. Simple Skewness 三分

Codeforces 558E A Simple Task

Codeforces 665C - Simple Strings

CodeForces 11D A Simple Task