C. As Simple as One and Two

 

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 
  1. one,刪除 n/e。

  2. two,刪除 t/w 。

  3. twone,刪除 o 。 

避免出現two…o…one

const int N=2e5+5;

    int n,m,t;
    int i,j,k;
    char s[N];

int main()
{
    IOS;
    rush(){
        cin>>s+1;
        vector<int> v;
        int len=strlen(s+1);
        for(i=1;i<=len;){
            if(i+2>len) break;
            if(s[i]=='o'&&s[i+1]=='n'&&s[i+2]=='e') v.push_back(i+1),i+=3;
            else if(s[i]=='t'&&s[i+1]=='w'&&s[i+2]=='o'){
                if(s[i+3]=='n'&&s[i+4]=='e') v.push_back(i+2),i+=5;
                else v.push_back(i+1),i+=3;
            }
            else i++;
        }
        cout<<v.size()<<endl;
        for(auto it:v) cout<<it<<" ";
        cout<<endl;
    }
    PAUSE;
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章