86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
void bubbleSort(int arr[], int n){
|
|
int i, j;
|
|
int temp;
|
|
for (i = 0; i < n-1; i++) {
|
|
for (j = 0; j < n - i - 1; j++) {
|
|
if (arr[j] > arr[j + 1]) {
|
|
temp = arr[j];
|
|
arr[j] = arr[j + 1];
|
|
arr[j + 1] = temp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
char glass[500];
|
|
char divided[10];
|
|
memset(divided, '\0', 10);
|
|
int counter = 0, counter2 = 0;
|
|
int final_count = 0;
|
|
int numbers[50];
|
|
int max_number = 0;
|
|
int max_positions[50];
|
|
int repeats = 1;
|
|
int user = 1;
|
|
|
|
|
|
fgets(glass, 500, stdin);
|
|
|
|
for (int i = 0; i < 500; i++){
|
|
if(!isdigit(glass[i]) && glass[i] != ' ' && glass[i] != '\n') {
|
|
final_count = i;
|
|
break;
|
|
}
|
|
|
|
if(glass[i] != ' ' && glass[i] != '\n'){
|
|
divided[counter++] = glass[i];
|
|
}
|
|
else {
|
|
if (glass[i-1] == ' ' && glass[i] == ' ') continue;
|
|
if(atoi(divided) < 1){
|
|
final_count = i;
|
|
break;
|
|
}
|
|
numbers[counter2++] = atoi(divided);
|
|
if (i == 0){
|
|
max_number = numbers[counter2-1];
|
|
}
|
|
else if (max_number < numbers[counter2-1]){
|
|
max_number = numbers[counter2-1];
|
|
repeats = 1;
|
|
max_positions[repeats-1] = user;
|
|
//max_position = i+1;
|
|
}
|
|
else if (max_number == numbers [counter2-1]){
|
|
repeats++;
|
|
max_positions[repeats-1] = user;
|
|
}
|
|
|
|
printf("Súťažiaci č. %d vypil %d pohárov.\n",user,numbers[counter2-1]);
|
|
//max_position = i+1;
|
|
counter = 0;
|
|
memset(divided, '\0', 10);
|
|
user++;
|
|
}
|
|
|
|
final_count = i;
|
|
if(glass[i] == '\n'){
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (final_count == 0)
|
|
printf("Chyba: Málo platných hodnôt.\n");
|
|
else {
|
|
for(int i = 0; i < repeats; i++)
|
|
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n",max_positions[i],max_number);
|
|
}
|
|
|
|
return 0;
|
|
} |