67 lines
1.4 KiB
C++
67 lines
1.4 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 07/03/2025
|
|
|
|
es5J: Scrivere una funzione che, ricevuta in input una
|
|
stringa, inserisca dopo ogni vocale la vocale successiva
|
|
('a'->'e', 'e'->'i', 'i'->'o', 'o'->'u', 'u'->'a').
|
|
Prototipo richiesto:
|
|
char *insertnextvowel(char * const str);
|
|
Esempio: superciao -> suapeircioaeou
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#define SIZE 200+1
|
|
|
|
using namespace std;
|
|
|
|
char *insertnextvowel(char * const str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cin.getline(str, SIZE);
|
|
|
|
cout << insertnextvowel(str);
|
|
|
|
return 0;
|
|
}
|
|
|
|
char *insertnextvowel(char * const str) {
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
str[i] = tolower(str[i]);
|
|
|
|
if (str[i] == 'a') {
|
|
memmove(str + i + 1, str + i, strlen(str) - i + 1);
|
|
str[i + 1] = 'e';
|
|
i++;
|
|
} else if (str[i] == 'e') {
|
|
memmove(str + i + 1, str + i, strlen(str) - i + 1);
|
|
str[i + 1] = 'i';
|
|
i++;
|
|
} else if (str[i] == 'i') {
|
|
memmove(str + i + 1, str + i, strlen(str) - i + 1);
|
|
str[i + 1] = 'o';
|
|
i++;
|
|
} else if (str[i] == 'o') {
|
|
memmove(str + i + 1, str + i, strlen(str) - i + 1);
|
|
str[i + 1] = 'u';
|
|
i++;
|
|
} else if (str[i] == 'u') {
|
|
memmove(str + i + 1, str + i, strlen(str) - i + 1);
|
|
str[i + 1] = 'a';
|
|
i++;
|
|
}
|
|
|
|
if (str[i] == '\0') {
|
|
if (!isalnum(str[i - 1])) {
|
|
str[i - 1] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
return str;
|
|
} |