54 lines
1.0 KiB
C++
54 lines
1.0 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 07/03/2025
|
|
|
|
es5D: Raddoppiare i caratteri corrispondenti alle
|
|
vocali che compaiono in una stringa str ricevuta in input.
|
|
Nota: le vocali dovranno essere raddoppiate "inplace",
|
|
senza usare stringhe di appoggio.
|
|
Prototipo richiesto:
|
|
char *dupvowels(char * const str);
|
|
Esempio:
|
|
"12 ottobre 1492" -> "12 oottoobree 1492"
|
|
"uomo" --> "uuoomoo"
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cstring>
|
|
#include <cctype>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
int isVowel(char chr);
|
|
char *dupvowels(char * const str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cin.getline(str, SIZE);
|
|
|
|
cout << dupvowels(str);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int isVowel(char chr) {
|
|
chr = toupper(chr);
|
|
|
|
return (chr == 'A' || chr == 'E' || chr == 'I' || chr == 'O' || chr == 'U');
|
|
}
|
|
|
|
char *dupvowels(char * const str) {
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (isVowel(str[i])) {
|
|
memmove(str + i + 1, str + i, strlen(str) + 1);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
return str;
|
|
} |