Advertisement
Guest User

Algoritmo: palindromo o no

a guest
Apr 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     char palabra[100], pal[100];
  9.    
  10.     cout << "Numero de letras que tiene la palabra: ";
  11.     cin >> n;
  12.    
  13.     cout << endl << "Palabra: ";
  14.    
  15.     for(int i = 1; i <= n; i++)
  16.     {      
  17.         cin >> palabra[i];
  18.     }
  19.    
  20.     int temp;
  21.     int c = n;
  22.  
  23.     for(int i = 1; i <= n; i++)
  24.     {
  25.         pal[i] = palabra[i];
  26.     }
  27.    
  28.     for(int i = 1; i <= n; i++)
  29.     {
  30.         temp = pal[i];
  31.         pal[i] = pal[c];
  32.         pal[c] = temp;
  33.         c--;
  34.     }
  35.    
  36.     cout << endl;
  37.     bool found = false;
  38.    
  39.     for(int i = 1; i <= n; i++)
  40.     {
  41.         if(pal[i] != palabra[n]){
  42.            
  43.             found = true;          
  44.         }  
  45.         n--;   
  46.     }
  47.    
  48.     if(found == false)
  49.     {
  50.         cout << "Es un palindromo" << endl;
  51.     } else
  52.     {
  53.         cout << "No es un palindromo" << endl;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement