inicializacia + zakladna logika
This commit is contained in:
parent
b915ec9466
commit
c342f6dffe
43
du4/program.c
Normal file
43
du4/program.c
Normal 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user