At the city informatics Olympiad, participants were asked to complete 3 tasks, each of which was rated on a 25-point scale. It is known that the total number of participants in the first round of the Olympiad does not exceed 250 people. At the entrance of the program are given information about the results of the Olympiad. The first line introduces the number of participants N. Next are N lines with the following format:
<Last Name> <Name> <Points>
Here, <Last Name> is a string consisting of no more than 20 characters; <Name> is a string consisting of no more than 15 characters; <Points> is a string containing three integers, separated by a space, corresponding to the points received by the participant for each task of the first round. In this case, <Last Name> and <Name>, <Name> and <Points> are separated by a single space. Examples of input lines:
Petrova Olga 25 18 16
Kalinichenko Ivan 14 19 15
Write a program that will display the name and surname of the participant who has scored the maximum number of points. If among the other participants there are students who have scored the same number of points, then their names and surnames should also be derived. In this case, the names and surnames can be displayed in any order.
Here is what I came up with:
#include <stdio.h> #include <math.h> #include <string.h> main(){ int dig[100];/*счетчик*/ char fam[19]; char name[14]; int i,j,n,c,st,rez1,rez2,rez3,rezmax,rez; printf("Кол-воо участников :\n"); scanf("%d",n); for (i = 0; i < n; i++ ){ dig[i] = 0;/*Все элементы счетчика равны нулю*/ } printf("\nВводите результаты:\n"); rezmax = 0; for (i = 0; i < n; i++ ){ scanf("%s %s %d %d %d",&fam,&name,&rez1,&rez2,&rez3); rez = rez1 + rez2 + rez3; dig[i] = rez; if(rez > rezmax){ rezmax = rez; } } }
Began to understand, I write:
#include <stdio.h> #include <math.h> #include <string.h> main(){ struct Rez { char fam[20]; char name[15]; int rez; } ; int rez1; int rez2; int rez3; struct Rez dig[100]; int i,j,n,tmp; printf("Введите число участников: \n"); scanf("%d",&n); printf("Введите имена и результаты участников: \n"); for (i = 0; i < n - 1; i++ ){ scanf("%s %s %d %d %d",&Rez.fam,&Rez.name,&rez1,&rez3,&rez3); Rez.rez = rez1 + rez2 + rez3; dig[i] = Rez; } for (i = n - 1; i >= 1; i-- ){ for (j = 0; j <= i; j++ ){ if (dig[i].rez > dig[j].rez){ tmp = dig[j]; dig[i] = dig[j]; dig[j] = tmp; } } } printf("\n%s %s %d",dig[n - 1].fam,dig[n - 1].name,dig[n - 1].rez); return 0; }
And to me in response:
ошибка: unknown type name «Rez»
with all that it implies. I repeat, I have about an hour of experience with textures. Where have I been wrong? Thank.
Corrected, now:
c2.c:22:29: ошибка: «Rez» undeclared (first use in this function) c2.c:22:29: замечание: each undeclared identifier is reported only once for each function it appears in c2.c:30:13: ошибка: incompatible types when assigning to type «int» from type «struct Rez» c2.c:32:16: ошибка: incompatible types when assigning to type «struct Rez» from type «int»
Where am I wrong?
Problems solved. Sorting an array of structures. , the topic can be closed.