Advertisement
informaticage

a a bronzatissima

Apr 1st, 2021
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. string leggi() {
  6.   string parola = "";
  7.   getline(cin, parola);
  8.   return parola;
  9. }
  10.  
  11. bool palindroma(string parola) {
  12.   int n = 0, i, j;
  13.   n = parola.length();
  14.   for (i = 0; i < n / 2; i++) {
  15.     for (j = n - 1; j > n / 2; j--) {
  16.       if (parola[i] == parola[j]) {
  17.         return true;
  18.       } else {
  19.         return false;
  20.         break;
  21.       }
  22.     }
  23.   }
  24. }
  25.  
  26. int main() {
  27.   string parola = "";
  28.   do {
  29.     cout << "Inserisci una parola e verifichero' se e' palindroma ";
  30.     parola = leggi();
  31.     if (parola.size() == 0) {
  32.       cout << "Arrivederci! ";
  33.     } else {
  34.       if (palindroma(parola) == true) {
  35.         cout << "\n La parola e' palindroma ";
  36.       } else
  37.         cout << "\n La parola non e' palindroma ";
  38.     }
  39.   } while (!(parola.size() == 0));
  40.   return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement