inicializacia + zakladna logika

This commit is contained in:
Aleš Novysedlák 2025-03-13 14:24:00 +01:00
parent b915ec9466
commit c342f6dffe

43
du4/program.c Normal file
View File

@ -0,0 +1,43 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main() {
char buffer[999];
char voting[99][10];
char names[99][50];
int count = 0;
while(fgets(buffer, sizeof(buffer), stdin) != NULL) {
char current_votes[10] = "";
char current_name[50] = "";
sscanf(buffer, "%s %[^\n]", current_votes, current_name);
int is_contained = 0;
for (int i=0; i<count; i++) {
if (strcmp(names[i], current_name) == 0) {
sprintf(voting[i], "%d", atoi(voting[i]) + atoi(current_votes));
is_contained = 1;
break;
}/*
else {
strcpy(names[count], current_name);
strcpy(voting[count], current_votes);
count++;
}*/
}
if (!is_contained) {
strcpy(names[count], current_name);
strcpy(voting[count], current_votes);
count++;
}
}
if (count == 0) {
return 1;
}
//printf("%s %s\n", voting[0], names[0]);
return 0;
}