Advertisement
rihardmarius

final 2a - capicua

Nov 23rd, 2013
412
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <array>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. struct pila {
  8.     array<int,10> arr;
  9.     int index = 0;
  10. };
  11.  
  12. void push (pila& p, int a)
  13. {
  14.     p.arr.at(p.index) = a;
  15.     p.index++;
  16. }
  17.  
  18. void pop (pila& p, int& a)
  19. {
  20.     a = p.arr.at(p.index - 1);
  21.     p.index--;
  22. }
  23.  
  24. int main()
  25. {
  26.     stringstream input;
  27.     int n, a, b; pila p; bool c = true;
  28.     input << "5  2 1 7 1 2";
  29.  
  30.     cout << "ingrese cantidad de elementos" << endl;
  31.     input >> n;
  32.  
  33.     cout << "ingrese los elementos de a uno" << endl;
  34.     for (int i=0; i<n/2; i++)
  35.     {
  36.         input >> a;
  37.         push (p, a);
  38.     }
  39.  
  40.     if (n%2==1)
  41.         input >> a;
  42.  
  43.     for (int i=0; i<n/2; i++)
  44.     {
  45.         input >> a;
  46.         pop (p, b);
  47.         if (a != b)
  48.             c = false;
  49.     }
  50.  
  51.     if (c)
  52.         cout << "es capicua" << endl;
  53.     else
  54.         cout << "no es capicua" << endl;
  55.  
  56.     return 0;
  57. }
Advertisement
RAW Paste Data Copied
Advertisement