pvjc24/cv2/program.c

68 lines
1.9 KiB
C
Raw Normal View History

2024-02-25 15:15:04 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
2024-02-25 16:44:42 +00:00
#define VELKOST_POLA 99
2024-02-25 15:15:04 +00:00
int array_of_quontiti_of_drinked_limonades(int *pole,int *array_of_winers);
int main(){
int pole[VELKOST_POLA];
memset(pole,0,VELKOST_POLA * sizeof(int));
int array_of_winers[VELKOST_POLA];
memset(array_of_winers,0,VELKOST_POLA * sizeof(int));
int i=array_of_quontiti_of_drinked_limonades(pole,array_of_winers);
if(i==0){
2024-02-25 16:46:02 +00:00
printf("Chyba: Málo platných hodnôt.");
2024-02-25 15:15:04 +00:00
}
for(int j=0; j<i; j++){
2024-02-25 16:43:21 +00:00
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n",array_of_winers[j]+1,pole[array_of_winers[j]]);
2024-02-25 15:15:04 +00:00
}
}
int array_of_quontiti_of_drinked_limonades(int *pole,int *array_of_winers){
int i=0;
2024-02-25 16:43:21 +00:00
int value[VELKOST_POLA * sizeof(int)];
2024-02-25 15:15:04 +00:00
int bigest_score=0;
int counter_of_rided_values=0;
2024-02-25 16:43:21 +00:00
int readed_quantity=reading_input(pole);
int winners_index=0;
for(int i=0; i<readed_quantity; i++){
printf("Súťažiaci č. %d vypil %d pohárov.\n",i+1,pole[i]);
if(pole[i]>bigest_score){
bigest_score=pole[i];
winners_index=0;
}
if(pole[i]==bigest_score){
array_of_winers[winners_index]=i;
winners_index++;
2024-02-25 15:15:04 +00:00
}
}
2024-02-25 16:43:21 +00:00
return winners_index;
}
int reading_input(int *pole){
char array_of_symbols[99];
int i=0;
int j=0;
char c;
while ((c = getchar()) != EOF) {
if (c!='\n' && c!=' ' && c!='\t' && (c > '9' || c < '0')){
break;
}
if(c >= '0' && c <='9'){
array_of_symbols[i]=c;
i++;
} else{
array_of_symbols[i]='\0';
if(i!=0){
pole[j]=atoi(array_of_symbols);
i=0;
j++;
}
}
}
return j;
2024-02-25 15:15:04 +00:00
}