Изменил(а) на 'du5/program.c'
This commit is contained in:
parent
d1f9a9efdc
commit
8b03000d68
@ -1,160 +1,82 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define SIZE 100
|
#define SIZE 100
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct student {
|
struct student {
|
||||||
|
|
||||||
char name[SIZE];
|
char name[SIZE];
|
||||||
|
|
||||||
int votes;
|
int votes;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int find_student(struct student* students, int size, const char* nameo){
|
int find_student(struct student* students, int size, const char* nameo){
|
||||||
|
|
||||||
int con = 0;
|
int con = 0;
|
||||||
|
|
||||||
for(int i = 0; i < size; i++){
|
for(int i = 0; i < size; i++){
|
||||||
|
|
||||||
if(strcmp (nameo, students[i].name) == 0){ // students[i].name вместо students.name[SIZE]
|
if(strcmp (nameo, students[i].name) == 0){ // students[i].name вместо students.name[SIZE]
|
||||||
|
|
||||||
con++;
|
con++;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(con == 0){
|
if(con == 0){
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
con = 0;
|
con = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
int STOP = 0;
|
int STOP = 0;
|
||||||
|
|
||||||
struct student databaza[SIZE];
|
struct student databaza[SIZE];
|
||||||
|
|
||||||
memset(databaza, 0, SIZE*sizeof(struct student));
|
memset(databaza, 0, SIZE*sizeof(struct student));
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
char line[SIZE];
|
char line[SIZE];
|
||||||
|
|
||||||
memset(line, 0, SIZE);
|
memset(line, 0, SIZE);
|
||||||
|
|
||||||
char* r;
|
char* r;
|
||||||
|
|
||||||
char* end = NULL;
|
char* end = NULL;
|
||||||
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
|
||||||
if (r == NULL){
|
if (r == NULL){
|
||||||
|
|
||||||
// Nastal koniec načítania
|
// Nastal koniec načítania
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while(STOP == 0){
|
while(STOP == 0){
|
||||||
|
|
||||||
r = fgets(line, SIZE, stdin);
|
r = fgets(line, SIZE, stdin);
|
||||||
|
|
||||||
if (r == NULL){
|
if (r == NULL){
|
||||||
|
|
||||||
STOP = 1;
|
STOP = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = strtol(line, &end, 10);
|
value = strtol(line, &end, 10);
|
||||||
|
|
||||||
//printf("value==>%d\n", value);
|
//printf("value==>%d\n", value);
|
||||||
|
|
||||||
//printf("end====>%s\n", end);
|
//printf("end====>%s\n", end);
|
||||||
|
|
||||||
char text[SIZE];
|
char text[SIZE];
|
||||||
|
|
||||||
memset(text, 0, SIZE);
|
memset(text, 0, SIZE);
|
||||||
|
|
||||||
char* zaciatok_mena = end + 1;
|
char* zaciatok_mena = end + 1;
|
||||||
|
|
||||||
int velkost_mena = strlen(zaciatok_mena) - 1;
|
int velkost_mena = strlen(zaciatok_mena) - 1;
|
||||||
|
|
||||||
//printf("zaciatok===>%s\n", zaciatok_mena);
|
//printf("zaciatok===>%s\n", zaciatok_mena);
|
||||||
|
|
||||||
//printf("velkost====>%d\n", velkost_mena);
|
//printf("velkost====>%d\n", velkost_mena);
|
||||||
|
|
||||||
if (velkost_mena > 0){
|
if (velkost_mena > 0){
|
||||||
|
|
||||||
memcpy(text, zaciatok_mena, velkost_mena);
|
memcpy(text, zaciatok_mena, velkost_mena);
|
||||||
|
|
||||||
//printf("text===>%s\n", text);
|
//printf("text===>%s\n", text);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
||||||
STOP = 1;
|
STOP = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int id = find_student(databaza, size, text);
|
int id = find_student(databaza, size, text);
|
||||||
|
|
||||||
if (id < 0){
|
if (id < 0){
|
||||||
|
|
||||||
memcpy(databaza[size].name, text, velkost_mena);
|
memcpy(databaza[size].name, text, velkost_mena);
|
||||||
|
|
||||||
databaza[size].votes = value;
|
databaza[size].votes = value;
|
||||||
|
|
||||||
size += 1;
|
size += 1;
|
||||||
|
|
||||||
//printf("value===>%d\n",value);
|
//printf("value===>%d\n",value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
||||||
databaza[id].votes += value;
|
databaza[id].votes += value;
|
||||||
|
|
||||||
//printf("data===>%d\n",databaza[id].votes);
|
//printf("data===>%d\n",databaza[id].votes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
|
||||||
printf("%d", databaza[i].votes);
|
printf("%d", databaza[i].votes);
|
||||||
|
|
||||||
printf(" %s\n", databaza[i].name);
|
printf(" %s\n", databaza[i].name);
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user