time limit per test3 seconds
memory limit per test256 megabytes
input: standard input
output: standard output
You are given a non-empty string s=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 s if there is an integer j(1≤j≤n−2), that sjsj+1sj+2=“one” or 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=“onetwone”, then if Polycarp selects two indices 3 and 6, 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 t(1≤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 s. Its length does not exceed 1.5⋅105. The string s 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⋅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 r(0≤r≤|s|) — the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers — the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo

Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11

题目大意:
给出一个字符串,删除部分字符(也可以不删),使字符没有连续的"one"或者"two"。
最近cf某场的div2的c题,一开始的策略出了点问题,导致连wa三发,罚时瞬间爆炸。策略很简单,如果是单独的"one"就把n删了,如果是单独的"two"就把w删了,就可以使类似"oooneee"这样的多个头跟尾字符的情况。而如果是"twone",就把o删了。第一次wa是因为没有做判断,for循环的指针也没有跳跃,使"twone"把o删了之后循环到"one"又把n给删了。之后加了个标识数组,蜜汁wa,最后直接把指针做了下跳跃处理就ac了。(脑子不清醒别随便打题.jpg)

代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
string s;
int a[100005];
int times,num; int main(){
cin>>t;
while(t--){
cin>>s;
times=0; num=0;
for(int i=0;i<s.size();i++){
if(s[i]=='o' && s[i+1]=='n'&& s[i+2]=='e'){
times++;
a[num++]=i+2;
i=i+2;
}else if(s[i]=='t' && s[i+1]=='w' && s[i+2]=='o'){
if(s[i+3]=='n' && s[i+4]=='e'){
times++;
a[num++]=i+3;
i=i+4;
}else{
times++;
a[num++]=i+2;
i=i+2;
}
}
}
cout<<times<<endl;
for(int i=0;i<num;i++){
cout<<a[i];
if(i!=num-1){
cout<<" ";
}
}
cout<<endl;
}
return 0; }

  


————————————————

CSDN链接:https://blog.csdn.net/weixin_43880627/article/details/103621781

As Simple as One and Two的更多相关文章

  1. PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)

    最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...

  2. Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】

    原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...

  3. WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION

    开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...

  4. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  5. 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 ...

  6. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  7. 设计模式之简单工厂模式Simple Factory(四创建型)

    工厂模式简介. 工厂模式专门负责将大量有共同接口的类实例化 工厂模式可以动态决定将哪一个类实例化,不必事先知道每次要实例化哪一个类. 工厂模式有三种形态: 1.简单工厂模式Simple Factory ...

  8. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  9. 关于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交叉 ...

  10. A Simple OpenGL Shader Example II

    A Simple OpenGL Shader Example II eryar@163.com Abstract. The OpenGL Shading Language syntax comes f ...

随机推荐

  1. Git实战指南----跟着haibiscuit学Git(第十一篇)

    笔名:  haibiscuit 博客园: https://www.cnblogs.com/haibiscuit/ Git地址: https://github.com/haibiscuit?tab=re ...

  2. 高强度学习训练第六天总结:Redis主从关系总结

    Redis主从复制机制 1.读写分离的好处 性能优化:主服务器专注于写操作,可以更适合写入数据的模式工作:同样,从服务器专注于读操作,可以用更适合读取数据的模式工作. 强化数据安全,避免单点故障:由于 ...

  3. idea中git分支、合并与使用

    1.分支的新建与合并使用场景介绍 让我们来看一个简单的分支新建与分支合并的例子,实际工作中你可能会用到类似的工作流. 你将经历如下步骤: 开发某个网站. 为实现某个新的需求.问题(#53问题),创建一 ...

  4. phpStorm+xdebug调试(php7.3)

    一.首先安装xdebug 安装xdebug比 ,运行php -i >phpinfo.txt 或者 echo phpinfo();将全部信息贴到https://xdebug.org/wizard. ...

  5. 通过 Telegraf + InfluxDB + Grafana 快速搭建监控体系的详细步骤

    第一部分 Telegraf 部署和配置 Telegraf 是实现 数据采集 的工具.Telegraf 具有内存占用小的特点,通过插件系统开发人员可轻松添加支持其他服务的扩展. 在平台监控系统中,可以使 ...

  6. 005.SQLServer AlwaysOn可用性组高可用简介

    一 AlwaysOn 可用性组 1.1 AlwaysOn 可用性组概述 AlwaysOn 可用性组功能是一个提供替代数据库镜像的企业级方案的高可用性和灾难恢复解决方案.SQL Server 2012 ...

  7. 【使用篇二】SpringBoot定时任务Scheduled(14)

    在日常项目运行中,我们总会有需求在某一时间段周期性的执行某个动作.比如每天在某个时间段导出报表,或者每隔多久统计一次现在在线的用户量.在springboot中可以有很多方案去帮我们完成定时器的工作,有 ...

  8. CSP2019 游记

    \(\text{CSP 2019}\) 游记 \[\text{草}\] \[\text{By:Luckyblock}\] \[Day\ -1:\] \(19:00\) 送行饭, 被摁在墙角干了 因为偏 ...

  9. Python 分析到底是谁操纵《庆余年》上了热搜?

    庆余年电视剧终于在前两天上了,这两天赶紧爬取数据看一下它的表现. ​ ​ 庆余年 ​ <庆余年>是作家猫腻的小说.这部从2007年就开更的作品拥有固定的书迷群体,也在文学IP价值榜上有名. ...

  10. windows系统搭建Python环境

    1.首先访问http://www.python.org/download/去下载最新的python版本. 2.安装下载包,一路next. 3.为计算机添加安装目录搭到环境变量,如图把python的安装 ...