1
This commit is contained in:
parent
5a44dac6c6
commit
ce33e08499
BIN
du4/program
Executable file
BIN
du4/program
Executable file
Binary file not shown.
58
du4/program.c
Normal file
58
du4/program.c
Normal file
@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SIZE 100
|
||||
|
||||
struct student {
|
||||
char name[SIZE];
|
||||
int votes;
|
||||
};
|
||||
|
||||
struct student databaza[SIZE];
|
||||
int size = 0;
|
||||
|
||||
int find_student(const char* name) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (strcmp(databaza[i].name, name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char line[SIZE];
|
||||
memset(databaza, 0, sizeof(databaza));
|
||||
|
||||
while (fgets(line, SIZE, stdin)) {
|
||||
char* end = NULL;
|
||||
int votes = strtol(line, &end, 10);
|
||||
|
||||
if (votes <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char name[SIZE];
|
||||
memset(name, 0, SIZE);
|
||||
strncpy(name, end + 1, strlen(end + 1) - 1);
|
||||
|
||||
int id = find_student(name);
|
||||
|
||||
if (id < 0) {
|
||||
strncpy(databaza[size].name, name, SIZE - 1);
|
||||
databaza[size].votes = votes;
|
||||
size++;
|
||||
} else {
|
||||
databaza[id].votes += votes;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Vysledky:\n");
|
||||
for (int i = 0; i < size; i++) {
|
||||
printf("%d %s\n", databaza[i].votes, databaza[i].name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user