跳到正文

题解

题解 CF1276A 【As Simple as One and Two】

gyh20约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年6月14日
更新
2026年6月14日
篇幅
约 2 分钟
题目
CF1276A

版本

  1. v1当前

贪心。

如果找到一个 oneone 那么删去中间的 nn 一定是最佳的。

如果是 twotwo 那么如果是 twonetwone 的情况,删去 oo 可以保证少删一个数,否则删去 ww 来保证准确性。

代码:

C++
#include<cstdio>
#include<queue>
#include<cstring>
#include<map>
#define re register
using namespace std;
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int pos[150002],num;
char s[150002];
int main(){
	int t,n;
	scanf("%d",&t);
	while(t--){
		scanf("%s",s+1);
		n=strlen(s+1);
		num=0;
		for(re int i=1;i<=n-2;++i){
			if(s[i]=='o'&&s[i+1]=='n'&&s[i+2]=='e')pos[++num]=i+1,s[i]='a';
			if(s[i]=='t'&&s[i+1]=='w'&&s[i+2]=='o')if(s[i+3]=='o'&&i<=n-3)pos[++num]=i+1;else pos[++num]=i+2,s[i+2]='a';
		}
		printf("%d\n",num);
		for(re int i=1;i<=num;++i)printf("%d ",pos[i]);
	//	printf("%s\n",s+1);
		putchar('\n');
	}
}
原文