Codeforces 1277C As Simple as One and Two

题目链接:

1277C As Simple as One and Two

思路:

1.如果有twone,我们肯定需要去掉o
2.如果有单独的one或者two,我们去掉中间一个字符即可;(思考一下就可以知道,因为留下的oeto不会和相邻的字符再组成one或者two

代码:

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
#define fi first
#define sc second
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pt(a) cerr<<a<<"---
"
#define rp(i,n) for(int i=0;i<n;i++)
#define rpn(i,n) for(int i=1;i<=n;i++)
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		int len=s.length();
		vector<int> v;
		for(int i=0;i<len;i++){
			if(i+5<=len){
				if(s.substr(i,5)=="twone"){
					v.pb(i+3),i+=4; continue;
				}
			}
			if(i+3<=len){
				string ss=s.substr(i,3);
				if(ss=="one"){
					v.pb(i+2),i+=2;
				}
				else if(ss=="two"){
					v.pb(i+2),i+=2;
				}
			}
		}
		cout<<v.size()<<'
';
		for(int x:v) cout<<x<<' '; cout<<'
';
	}
	return 0;
}
原文地址:https://www.cnblogs.com/yuhan-blog/p/12308734.html