As Simple as One and Two
memory limit per test256 megabytes
input: standard input
output: standard output
For example:
Polycarp likes strings “oonnee”, “twwwo” and “twnoe” (they have no substrings “one” and “two”).
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?
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.
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.
4
onetwone
testme
oneoneone
twotwo
2
6 3
0
3
4 1 7
2
1 4
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的更多相关文章
- 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交叉 ...
- A Simple OpenGL Shader Example II
A Simple OpenGL Shader Example II eryar@163.com Abstract. The OpenGL Shading Language syntax comes f ...
随机推荐
- PHP+jQuery中国地图热点数据统计展示实例
一款PHP+jQuery实现的中国地图热点数据统计展示实例,当鼠标滑动到地图指定省份区域,在弹出的提示框中显示对应省份的数据信息. 首先在页面中加一个div#tip,用来展示地图信息的提示框和#map ...
- Class文件结构-属性表
一.属性表整体结构 二.属性表具体结构
- ES6 ... 展开&收集运算符
...展开&收集运算符,也就是说他可以干两件事情,展开和收集 一:收集,顾名思义把散列东西收集到一个地方,这个地方ES6规定收集在数组中 例如:下面函数fn将传递的参数收集在arg变量中,打印 ...
- IntelliJ IDEA 2019.2.2同个项目运行多次的方法
IntelliJ IDEA默认运行项目后,再点击运行就是重启,但有时候,需要配置项目的不同端口号,同时运行. 步骤如下: 1.点击IDEA右上角项目的隐藏下拉框,出现下拉列表,点击Edit Confi ...
- 阿里云RDS for SQL Serrver关于权限的一个严重Bug
阿里云RDS for SQL Server的账号管理有不少小Bug,而且有一个很严重的Bug:任何普通账号,都能创建数据库.注意,我这里是说任意普通账号,任意任意普通账号!任意任意普通账号!重要的事情 ...
- SQL Server获取索引创建时间&重建时间&重组时间
之前写过一篇博客"SQL Server中是否可以准确获取最后一次索引重建的时间?",里面主要讲述了三个问题:我们能否找到索引的创建时间?最后一次索引重建(Index Rebuild ...
- 表单生成器(Form Builder)之伪造表单数据mongodb篇
这篇文章终于回到了正轨:为mongodb伪造数据.之前的随机数.随机车牌照.随机时间还有这篇笔记中的获取指定长度的中文字符串,都是为这篇笔记做准备.看一下我们的准备(基础代码) // 1.获取指定范围 ...
- subprocess之check_out用法
在python3中使用subprocess的check_out方法时,因为该输出为byte类型,所以如果要查看具体的内容时需要进行转码,如果转码不对话,会影响内容输出的可读性,如下: #1,输出解码不 ...
- gunicorn Python部署应用
对于flask应用 启动命令为 python app.py 使用gunicorn启动 pip install gunicorn python gunicorn --workers=7 switch_a ...
- Java的反射机理
Java反射是一种间接操作目标对象的机制,核心是JVM在运行的时候才动态加载类,并且对于任意一个类,都能够知道这个类的全部属性和方法等,调用方法以及访问属性,而且不需要提前在编译期知道运行的对象是什么 ...