Advertisement
Emanuele_Bruno

Data una stringa a, dire se e' palindroma

Nov 12th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string a;
  8.     int m,i;
  9.     bool palindrome=true;
  10.     cout << "Digitare la stringa :" << endl;
  11.     cin >> a;
  12.     m=a.length();
  13.     i=0;
  14.     while (i<int(m/2))
  15.         {
  16.             if (a.substr(i,1)==a.substr((m-i-1),1)) i++;
  17.             else
  18.                 {
  19.                     palindrome=false;
  20.                     i=m; //imposto i=m per uscire subito dal ciclo while
  21.                 }
  22.         }
  23.     if (palindrome) cout << "Sono palindrome :)";
  24.     else cout << "Non sono palindrome :(";
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement