Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- string a;
- int m,i;
- bool palindrome=true;
- cout << "Digitare la stringa :" << endl;
- cin >> a;
- m=a.length();
- i=0;
- while (i<int(m/2))
- {
- if (a.substr(i,1)==a.substr((m-i-1),1)) i++;
- else
- {
- palindrome=false;
- i=m; //imposto i=m per uscire subito dal ciclo while
- }
- }
- if (palindrome) cout << "Sono palindrome :)";
- else cout << "Non sono palindrome :(";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement