58 lines
1.0 KiB
C++
58 lines
1.0 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cstring>
|
|
#include <cctype>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
bool isVowel(char chr);
|
|
bool isSymmetricVowel(const char *const str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cout << "Inserisci una parola: ";
|
|
cin.getline(str, SIZE);
|
|
|
|
if (isSymmetricVowel(str)) {
|
|
cout << "Le vocali sono simmetriche!" << endl;
|
|
} else {
|
|
cout << "Le vocali non sono simmetriche!" << endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
bool isVowel(char chr) {
|
|
return (chr == 'A' || chr == 'a'
|
|
|| chr == 'E' || chr == 'e'
|
|
|| chr == 'I' || chr == 'i'
|
|
|| chr == 'O' || chr == 'o'
|
|
|| chr == 'U' || chr == 'u');
|
|
}
|
|
|
|
bool isSymmetricVowel(const char *const str) {
|
|
if (*str != '\0') {
|
|
for (const char *pl = str, *pr = str + strlen(str) - 1; pl < pr; pl++, pr--) {
|
|
while (*pl != '\0' && !isVowel(*pl)) {
|
|
pl++;
|
|
}
|
|
|
|
while (pr >= str && !isVowel(*pr)) {
|
|
pr--;
|
|
}
|
|
|
|
if (pl < pr && tolower(*pl) != tolower(*pr)) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
} |