I have tried to solve this problem (using c++) but my answers are not the same those in the tests. Help, please!
Question:
In chats, it is very common among young people and teenagers to use sequences of letters, which often seem random, to reproduce. Some common examples are:
huaauhahhuahau
hehehehe
ahahahaha
jaisjjkasjksjjskjakijs
huehuehue
Cláudia is a young programmer who was intrigued by the sound of “digital laughs”. Some of them she can't even hear! But she realized that some of them seem to convey the feeling of laughter better than others. The first thing she realized is that consonants do not interfere with how much digital laughter influences the transmission of feeling. The second thing she realizes is that the funniest digital letters are those in which the vowel sequences are the same when natural order (left to right) or reverse order (from right to left) orders ignore as consonants. For example, "hahaha" and "huaauhahhuahau" are among the funniest, while "riajkjdhhihhjak" and "huehuehue" are not among the funniest. Cláudia is very busy with a statistical analysis of digital laughs and asked for her help to write a program that determines, for a digital laugh, if she is one of the funniest ones or not.
Input:
The entry consists of a line, contains a sequence of a maximum of 50 characters, formed only by lowercase letters without accents. As vowels are like letters 'a', 'and', 'i', 'o', 'u'. The string contains at least one vowel.
Output:
Your program should produce a line that contains a character, "S", if it appears, either the funniest or "N" otherwise.
Tests
hahaha S
riajkjdhhihhjak N
huaauhahhuahau S
a S
My code
#include <iostream>
using namespace std;
int main(){
string laugh, vowel;
int j=0, count = 0;
cin >> laugh;
for(int i = 0; i < laugh.size() ; i++ ){
if(laugh[i]=='a'){
vowel[j]='a';
j++;
}
if(laugh[i]=='e'){
vowel[j]='e';
j++;
}
if(laugh[i]=='i'){
vowel[j]='i';
j++;
}
if(laugh[i]=='o'){
vowel[j]='o';
j++;
}
if(laugh[i]=='u'){
vowel[j]='u';
j++;
}
}
for(int i = 0, j = (vowel.size()-1); i < vowel.size(); i++, j--){
if(vowel[i] != vowel[j]){
count++;
}
}
if(count==0){
cout << "S";
}
if(count!=0){
cout << "N";
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire