57 lines
1.4 KiB
C
57 lines
1.4 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
#define MAX_CONTESTANTS 50
|
||
|
|
||
|
int main() {
|
||
|
int results[MAX_CONTESTANTS];
|
||
|
int num_results = 0;
|
||
|
int max_cups = 0;
|
||
|
|
||
|
// Read and process input
|
||
|
while (1) {
|
||
|
int value;
|
||
|
if (scanf("%d", &value) != 1) {
|
||
|
printf("Chyba: Nesprávny vstup.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
if (value < 1) {
|
||
|
printf("Chyba: Nesprávna hodnota.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
if (num_results >= MAX_CONTESTANTS) {
|
||
|
printf("Chyba: Príliš veľa hodnôt.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
results[num_results++] = value;
|
||
|
|
||
|
char next_char = getchar();
|
||
|
if (next_char == '\n' || next_char == EOF) {
|
||
|
break;
|
||
|
}
|
||
|
ungetc(next_char, stdin);
|
||
|
}
|
||
|
|
||
|
if (num_results == 0) {
|
||
|
printf("Chyba: Málo platných hodnôt.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
// Find the maximum number of cups drunk
|
||
|
for (int i = 0; i < num_results; i++) {
|
||
|
if (results[i] > max_cups) {
|
||
|
max_cups = results[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Print results and winners
|
||
|
for (int i = 0; i < num_results; i++) {
|
||
|
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]);
|
||
|
if (results[i] == max_cups) {
|
||
|
printf("Výherca je súťažiaci č. %d ktorý vypil %d pohárov.\n", i + 1, results[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|