Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. /*
  2.  - Practica 1
  3.  - heyshir
  4. */
  5.  
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. const int MAXNUM = 20;
  10. const int MAXCOMP = 10;
  11.  
  12. struct numeros {
  13.     int n;
  14.     int r;
  15. };
  16.  
  17.     numeros num[MAXNUM];
  18.     numeros comp[MAXCOMP];
  19.  
  20. int comparar_introducido(int &x, int &c);
  21. int mas_repetido ();
  22.  
  23. int main() {
  24.  
  25.     int valor = 0;
  26.     bool ok = false;
  27.     for (int a = 1; a <= MAXNUM; a++) {
  28.         ok = 0;
  29.         while (ok != true) {
  30.             cout << "Introduca el valor numero " << a << endl;
  31.             cout << "--> ";
  32.             cin >> valor;
  33.             if ((valor >= 1) and (valor <= MAXCOMP)) {
  34.                 num[a].n = valor;
  35.                 num[a].r = 0;
  36.                 ok = true;
  37.             }
  38.             else {
  39.                 cout << "**El valor es erroneo**" << endl;
  40.             }
  41.         }
  42.     }
  43.     int x = 0;
  44.     ok = false;
  45.     while (ok != true) {
  46.         cout << "Introduzca el numero a comparar" << endl;
  47.         cin >> x;
  48.         if ((x >= 1) and (x <=10)) {
  49.             ok = true;
  50.         }
  51.         else {
  52.             cout << "**El valor es erroneo**" << endl;
  53.         }
  54.     }
  55.     int c = 0;
  56.     comparar_introducido (x, c);
  57.     cout << "El numero " << x << " aparece " << c << " veces en la lista" << endl;
  58.     mas_repetido ();
  59.     //system ("pause");
  60. }
  61.  
  62. int comparar_introducido(int &x, int &c) {
  63.     for (int a = 1; a <= MAXNUM; a++) {
  64.         if (x == num[a].n) {
  65.             c++;
  66.         }
  67.     }
  68. }
  69.  
  70. int mas_repetido () {
  71.     for (int e = 1; e <= MAXCOMP; e++) { //inicializamos el segundo vector
  72.         comp[e].n = e;
  73.         comp[e].r = 0;
  74.     }
  75.     for (int e = 1; e <= MAXCOMP; e++) {
  76.         for (int a = 1; a <= MAXNUM; a++) {
  77.         if (comp[e].n == num[a].n) {
  78.           int c = 0;
  79.           comparar_introducido(comp[e].n, c);
  80.           comp[e].r = c;
  81.         }
  82.        
  83.         }
  84.      
  85.      
  86.     }
  87.     int repe = 0, y;
  88.     for (int a = 1; a <= MAXCOMP; a++) {
  89.         if (comp[a].r > repe) {
  90.             repe = comp[a].r;
  91.             y = comp[a].n;
  92.         }
  93.     }
  94.     cout << "El valor ams repetido es " << y << " con " << repe << " veces" << endl;
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement