From 26284ed13aed64a7863f64935ca9d4297e0e78eb Mon Sep 17 00:00:00 2001 From: Bohdan Yanchyk Date: Mon, 2 Mar 2020 19:16:10 +0000 Subject: [PATCH] =?UTF-8?q?Aktualizovat=20=E2=80=9Edu2/program.c=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du2/program.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/du2/program.c b/du2/program.c index fc7eeb5..3d0ab09 100644 --- a/du2/program.c +++ b/du2/program.c @@ -1,34 +1,39 @@ #include -#define VELKOST_POLA 12 +#define VELKOST_POLA 50 int main() { - int value = 0; int pole[VELKOST_POLA] = {0,0,0,0}; - int r = 0; - int i = 0; - int max_hodnota = pole[0]; - while (r = scanf("%d",&value)){ - pole[i] = value; - i++; - } - - int len = (sizeof(pole)/sizeof(*pole)); - - for(i = 0; i < len; i++){ - if(pole[i] > max_hodnota){ - max_hodnota = pole[i]; + int i = 0, max_hodnota = 0, quant_max = 0, value = 0, indexMan = 0; + while(value >= 0 || i <= 49 || value != EOF){ + int r = scanf("%d",&value); + + if(value <= -1){ + break; + } + + if(max_hodnota < value){ + max_hodnota = value; + indexMan = i+1; + quant_max = 0; + } else if(max_hodnota == value){ + quant_max++; + } + + if(r == 1){ + pole[i] = value; + i++; + + fprintf(stdout, "Súťažiaci č. %d vypil %d pohárov.\n", i, pole[i-1]); + } else{ + break; } } - printf("%d", max_hodnota); + printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", indexMan, max_hodnota); - - free(max_hodnota); - free(i); - free(r); - free(value); return 0; } +