Обновить du1/program.cv
This commit is contained in:
parent
17a7fd14e2
commit
e8c1836d52
@ -1,34 +1,40 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#define MAX_CONTESTANTS 50
|
#define MAX_SIZE 50
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int results[MAX_CONTESTANTS];
|
int results[MAX_SIZE];
|
||||||
int count = 0, value;
|
int count = 0;
|
||||||
|
int num;
|
||||||
|
|
||||||
while (count < MAX_CONTESTANTS) {
|
while (count < MAX_SIZE && scanf("%d", &num) == 1) {
|
||||||
if (scanf("%d", &value) != 1 || value < 1) {
|
if (num < 1) {
|
||||||
printf("Chyba: Málo platných hodnôt.\n");
|
printf("Chyba: Málo platných hodnôt.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
results[count++] = value;
|
results[count++] = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 0) {
|
||||||
|
printf("Chyba: Málo platných hodnôt.\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_value = 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_value) {
|
if (results[i] > max_val) {
|
||||||
max_value = results[i];
|
max_val = results[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (results[i] == max_value) {
|
if (results[i] == max_val) {
|
||||||
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user