Обновить du1/program.c
This commit is contained in:
parent
86c2edc97e
commit
23aa940839
@ -1,43 +1,39 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#define MAX_SIZE 50
|
#define VELKOST_POLA 50
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int results[MAX_SIZE];
|
int results[VELKOST_POLA];
|
||||||
|
memset(results, 0, sizeof(results));
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int num;
|
int value;
|
||||||
|
while (count < VELKOST_POLA) {
|
||||||
while (count < MAX_SIZE && scanf("%d", &num) == 1) {
|
if (scanf("%d", &value) != 1) {
|
||||||
if (num < 1) {
|
break;
|
||||||
printf("Chyba: Málo platných hodnôt.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
results[count++] = num;
|
if (value < 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
results[count++] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
printf("Chyba: Málo platných hodnôt.\n");
|
printf("Chyba: Málo platných hodnôt.\n");
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]);
|
printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]);
|
||||||
}
|
}
|
||||||
|
int max = results[0];
|
||||||
int max_val = INT_MIN;
|
for (int i = 1; i < count; i++) {
|
||||||
for (int i = 0; i < count; i++) {
|
if (results[i] > max) {
|
||||||
if (results[i] > max_val) {
|
max = results[i];
|
||||||
max_val = results[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (results[i] == max_val) {
|
if (results[i] == max) {
|
||||||
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]);
|
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, results[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user