fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. // Declarar e inicializar el vector
  7. vector<int> vec = {1, 2, 3, 2, 1}; // Cambia los valores para probar
  8. int n = vec.size(); // Tamaño del vector
  9.  
  10. // Verificar si el vector es un palíndromo
  11. bool isPalindrome = true;
  12. for (int i = 0; i < n / 2; i++) {
  13. if (vec[i] != vec[n - 1 - i]) {
  14. isPalindrome = false;
  15. break;
  16. }
  17. }
  18.  
  19. // Mostrar el resultado
  20. if (isPalindrome) {
  21. cout << "El vector es un palíndromo." << endl;
  22. } else {
  23. cout << "El vector no es un palíndromo." << endl;
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
El vector es un palíndromo.