1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <cstdlib>
#include <cctype>
#include <random>
#include <chrono>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class GeneradorAleatorioEnteros
{
private:
mt19937 generador_mersenne; // Mersenne twister
uniform_int_distribution<int> distribucion_uniforme;
/************************************************************************/
long long Nanosec(){
return (chrono::high_resolution_clock::now().
time_since_epoch().count());
}
/************************************************************************/
public:
/************************************************************************/
GeneradorAleatorioEnteros()
:GeneradorAleatorioEnteros(0, 1){
}
/************************************************************************/
GeneradorAleatorioEnteros(int min, int max) {
const int A_DESCARTAR = 70000;
// ACM TOMS Volume 32 Issue 1, March 2006
auto semilla = Nanosec();
generador_mersenne.seed(semilla);
generador_mersenne.discard(A_DESCARTAR);
distribucion_uniforme = uniform_int_distribution<int> (min, max);
}
/************************************************************************/
int Siguiente(){
return (distribucion_uniforme(generador_mersenne));
}
/************************************************************************/
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int * PosMayor (int *pv, int dcha = 99, int izda = 0){
int * p = pv + izda;
int *pos_max;
int max = 0;
// Bucle en el que avanzo valores mientras sean dígitos.
for (;p < pv + dcha; p++){
if (*p > max){
max = *p;
pos_max = p;
}
}
return (pos_max);
}
void RellenaEntero (int * pv, int dcha = 99, int izda = 0){
int limite_superior = 500;
int limite_inferior = 0;
int * p = pv;
GeneradorAleatorioEnteros generador_aleatorio(limite_inferior, limite_superior);
while (p < pv + dcha){
*p = generador_aleatorio.Siguiente();
p++;
}
}
int main(int argc, char ** argv){
const int TOPE = 100;
int vp[TOPE];
int * max;
int total, pos_max, pos_min;
if (argc == 1){
RellenaEntero (vp);
max = PosMayor(vp);
}
if (argc == 2){
total = atoi(argv [1]);
RellenaEntero (vp, total);
max = PosMayor(vp, total);
}
if (argc == 3){
total = atoi(argv[1]);
pos_min = atoi(argv[2]);
RellenaEntero (vp, total);
max = PosMayor(vp, total, pos_min);
}
if (argc == 4){
total = atoi(argv[1]);
pos_min = atoi(argv[2]);
pos_max = atoi(argv[3]);
RellenaEntero (vp, total);
max = PosMayor(vp,pos_max,pos_min);
}
if (argc > 4)
cout << "\tNumero maximo de argumetos sobrepasado";
cout << "\tEl maximo es: " << *max;
}
|