Advertisement
ProgramoBien

Detecta palindromos (C++)

Feb 1st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool palindromo(string &s);
  6.  
  7. int main()
  8. {
  9.     string s="racecar";
  10.     while(cin>>s){
  11.         if(s=="end")
  12.             break;
  13.         if(palindromo(s))
  14.             cout<<"Es palindromo";
  15.         else cout<<"No es";
  16.         cout<<"\n"; //endl
  17.     }
  18.     cout<<"He salido y ahora termino\n";
  19. }
  20.  
  21. bool palindromo(string &s){
  22.     for(int i=0;i<s.length()/2;i++){
  23.         if(s[i]!=s[s.length()-1-i])
  24.             return false;
  25.     }
  26.     return true;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement