kod co by mohol fungovat bez kontroly vstupu
This commit is contained in:
parent
92a61061c7
commit
d4e8985792
@ -1,7 +1,42 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
|
||||
char c = getchar();
|
||||
char loading_string[999] = {};
|
||||
int string_index = 0;
|
||||
while(c != EOF) {
|
||||
loading_string[string_index] = c;
|
||||
string_index++;
|
||||
c = getchar();
|
||||
}
|
||||
loading_string[string_index] = '\0';
|
||||
int iterating_index = 0;
|
||||
int user_counter = 1;
|
||||
int max_number_user_pair[2] = {0,0};
|
||||
int starting_index = 0;
|
||||
while(starting_index<string_index) {
|
||||
while (loading_string[iterating_index] != ' ') {
|
||||
iterating_index++;
|
||||
}
|
||||
iterating_index++;
|
||||
int number_size = iterating_index-starting_index-1;
|
||||
int current_number = 0;
|
||||
for (int l=0;l<number_size;l++) {
|
||||
int temporary_number = loading_string[starting_index+l]-'0';
|
||||
for (int k=number_size-1;k>0;k--) {
|
||||
temporary_number = temporary_number * 10;
|
||||
}
|
||||
current_number += temporary_number;
|
||||
}
|
||||
if (current_number > max_number_user_pair[0]) {
|
||||
max_number_user_pair[0] = current_number;
|
||||
max_number_user_pair[1] = user_counter;
|
||||
}
|
||||
printf("Súťažiaci č. %d vypil %d pohárov.\n", user_counter, current_number);
|
||||
user_counter++;
|
||||
starting_index = iterating_index + 1;
|
||||
}
|
||||
printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n",max_number_user_pair[1], max_number_user_pair[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user