From 8b03000d68080b6e60c20f265604c7cf164a2ade Mon Sep 17 00:00:00 2001 From: Vladyslav Korzun Date: Thu, 16 Mar 2023 07:50:47 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'du5/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du5/program.c | 84 ++------------------------------------------------- 1 file changed, 3 insertions(+), 81 deletions(-) diff --git a/du5/program.c b/du5/program.c index de947ed..c7c4d17 100644 --- a/du5/program.c +++ b/du5/program.c @@ -1,160 +1,82 @@ #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; - - } - + break; + } 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; - + break; } - 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; - } -