codeforces1276A As Simple as One and Two
3 seconds
256 megabytes
standard input
standard output
You are given a non-empty string s=s1s2…sns=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 (1≤j≤n−21≤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?
The first line of the input contains an integer tt (1≤t≤1041≤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.5⋅1051.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.5⋅1061.5⋅106.
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain rr (0≤r≤|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\n",v.size());
for(vector<int>::iterator it=v.begin() ;it!=v.end() ;it++ )
printf("%d ",*it);
printf("\n");
}
return 0;
}
codeforces1276A As Simple as One and Two的更多相关文章
- PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)
最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...
- Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】
原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...
- WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION
开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- 设计模式之简单工厂模式Simple Factory(四创建型)
工厂模式简介. 工厂模式专门负责将大量有共同接口的类实例化 工厂模式可以动态决定将哪一个类实例化,不必事先知道每次要实例化哪一个类. 工厂模式有三种形态: 1.简单工厂模式Simple Factory ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- 关于The C compiler "arm-none-eabi-gcc" is not able to compile a simple test program. 的错误自省...
在 GCC ARM Embedded https://launchpad.net/gcc-arm-embedded/ 上面下载了个arm-none-eabi-gcc 用cmake 编译时 #指定C交叉 ...
随机推荐
- 《学渣Linux笔记》——关于.bashrc与profile(涉及交互式与非交互式、登录与非登录shell)
<学渣Linux笔记>--关于.bashrc与profile(涉及交互式与非交互式.登录与非登录shell) 1.基本概念(个人理解) 交互式shell:等待用户输入,并执行相应操作的sh ...
- 用python编写一个搜索引擎
完整代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- import sys import os import datetime from PyQt5 ...
- MEF在WCF REST中实际应用2(Global.asax注册)
IOCContainer文件: public class IOCContainer { /// <summary> /// 容器 /// </summary> public s ...
- 七牛云图床存储+Alfread工作流+使用QSHELL
layout: post title: 七牛云图床存储+Alfread工作流+使用QSHELL 来源:http://www.cnblogs.com/cmi-sh-love/p/8901620.html ...
- loj#10013 曲线(三分)
题目 #10013. 「一本通 1.2 例 3」曲线 解析 首先这个题保证了所有的二次函数都是下凸的, \(F(x)=max\{s_i(x)\}i=1...n\)在每一个x上对应的最大的y,我们最后得 ...
- Java自学-类和对象 构造方法
怎么使用 Java 构造方法? 通过一个类创建一个对象,这个过程叫做实例化 实例化是通过调用构造方法(又叫做构造器)实现的 步骤 1 : 什么是构造方法 方法名和类名一样(包括大小写) 没有返回类型 ...
- 在Linux系统中创建SSH服务器别名
如果你经常通过 SSH 访问许多不同的远程系统,这个技巧将为你节省一些时间.你可以通过 SSH 为频繁访问的系统创建 SSH 别名,这样你就不必记住所有不同的用户名.主机名.SSH 端口号和 IP 地 ...
- np.random模块的使用介绍
np.random模块常用的一些方法介绍 名称 作用 numpy.random.rand(d0, d1, …, dn) 生成一个[d0, d1, …, dn]维的numpy数组,数组的元素取自[0, ...
- 前端构建工具 Gulp 压缩合并JS/CSS 并添加版本号、ES6转ES5
Gulp 基于 Node.js 的前端构建工具,可以实现前端代码的编译(sass.less).压缩合并(JS.CSS).测试:图片的压缩:已经添加 JS 和 CSS 版本号,防止浏览器缓存. 1. 安 ...
- 结对项目(python) 黄浩伟 黄飞越
作者:黄浩伟 黄飞越 一 .Github项目地址: https://github.com/Flying123haha/123.git 二.psp表格: PSP2.1 Personal Softwar ...