Help me with my CODETOWN program

include
include
using namespace std;

int main() {
int t;
cin>>t;
for(int i=0;i<t;i++){
string s;
cin>>s;
string p=“CODETOWN”;
string v=“AEIOU”;
int c=0;
int d=0;
for(int j=0; j<8;j++){

       for(int k=0; k<5;k++){
           if(s[j]==v[k]){
               c++;
               d=d+j;
           }
       }
    }
    if(c==3 && d==9 && p.length()==s.length()){
        cout<<"YES\n";
    }
    else{
        cout<<"NO\n";
	    }
        
        
   
}            


return 0;

}
#i think this is the right code please help me find where i’m mistaken

I think your code will give YES for OCDTEOWN, which should not be the case.
You have constrained the number of vowels but not their positions, as I can always move a vowel k units right and a previous one k units left to preserve the sum of positions to 9.
Hope this helps! :slight_smile:

Oh ! thank you so much ,now i get it .You’re a lifesaver.

1 Like