From d1f9a9efdcda6610b566fea3173347b8ff239d96 Mon Sep 17 00:00:00 2001 From: Vladyslav Korzun Date: Thu, 16 Mar 2023 07:41:59 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB(=D0=B0)=20?= =?UTF-8?q?'du5/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du5/program.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 du5/program.c diff --git a/du5/program.c b/du5/program.c new file mode 100644 index 0000000..de947ed --- /dev/null +++ b/du5/program.c @@ -0,0 +1,160 @@ +#include + +#include + +#include + +#include + +#include + +#include + +#define SIZE 100 + + + +struct student { + + char name[SIZE]; + + int votes; + +}; + + + +int find_student(struct student* students, int size, const char* nameo){ + + int con = 0; + + for(int i = 0; i < size; i++){ + + if(strcmp (nameo, students[i].name) == 0){ // students[i].name вместо students.name[SIZE] + + con++; + + return i; + + } + + } + + if(con == 0){ + + return -1; + + } + + con = 0; + +} + + + +int main(){ + + int STOP = 0; + + struct student databaza[SIZE]; + + memset(databaza, 0, SIZE*sizeof(struct student)); + + int size = 0; + + char line[SIZE]; + + memset(line, 0, SIZE); + + char* r; + + char* end = NULL; + + int value = 0; + + if (r == NULL){ + + // Nastal koniec načítania + + } + + while(STOP == 0){ + + r = fgets(line, SIZE, stdin); + + if (r == NULL){ + + STOP = 1; + + } + + value = strtol(line, &end, 10); + + //printf("value==>%d\n", value); + + //printf("end====>%s\n", end); + + char text[SIZE]; + + memset(text, 0, SIZE); + + char* zaciatok_mena = end + 1; + + int velkost_mena = strlen(zaciatok_mena) - 1; + + //printf("zaciatok===>%s\n", zaciatok_mena); + + //printf("velkost====>%d\n", velkost_mena); + + if (velkost_mena > 0){ + + memcpy(text, zaciatok_mena, velkost_mena); + + //printf("text===>%s\n", text); + + } + + else { + + STOP = 1; + + } + + int id = find_student(databaza, size, text); + + if (id < 0){ + + memcpy(databaza[size].name, text, velkost_mena); + + databaza[size].votes = value; + + size += 1; + + //printf("value===>%d\n",value); + + } + + else { + + databaza[id].votes += value; + + //printf("data===>%d\n",databaza[id].votes); + + } + + for (int i = 0; i < size; i++) { + + printf("%d", databaza[i].votes); + + printf(" %s\n", databaza[i].name); + + printf("\n"); + +} + + } + + return 0; + +} +