1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
| #include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream.h>
#define DL_NUM 3 /* nomer uchastnica */
#define DL_FIO 25 /* dlina polya familii v fayle */
#define DL_SCHOOL 5 /* dlina polya nomera school */
#define DL_BALL 7 /* dlina polya 5 ocenok + '\n'+'\0' */
#define DL_SUM 3 /*dlina polya summi ballov*/
struct olimpiada /* struktura zapisi vkhodnogo fayla */
{ char num[DL_NUM]; /* nomer uchastnika */
char fio[DL_FIO]; /* familiya i initsialy patsi */
char school[DL_SCHOOL]; /* nomer school */
char ball[DL_BALL]; /* spisok ballov */
char sum[DL_SUM];
};
/* Prototipy funktsiy */
void POBEDIT(FILE *f);
/*--------------------*/
/* Glavnaya funktsiya */
/*--------------------*/
int main()
{
FILE *f; /* ssylka na vkhodnoy fayl */
char n; /* nomer punkta menyu */
clrscr();
f= fopen("olimpia.txt","r");
if (f==NULL)
{ puts("File olimpia.txt ne najden");
getch();
return 1;
}
do
{ puts ("\n========================================================");
puts ("Vyberite nomer punkta menyu:");
puts ("1 - vyvod FIO pobediteley,zanjavschie pervie 3 mesta");
puts ("2 - vihod");
puts ("------------------------------------------------------");
n = getche();
switch(n)
{
case '1': POBEDIT(f); break;
case '2': break;
default: puts("\nNuzhno vvodit nomer punkta ot 1 do 2");
}
if (n!='2')
{ puts("\nDlya prodolzheniya nazhmite lyubuyu klavishu");
getch();
}
}
while (n!= '2');
fclose(f);
return 0;
}
/*--------------------------------------*/
/* Funktsiya vyvoda spiska pobediteley, */
/* zanjavschie pervie 3 mesta */
/*--------------------------------------*/
void POBEDIT(FILE *f)
{
struct olimpiada tz;
const int N=5;
int i,n=0,S[N];
char max1,max2,max3;
char fio[81];
char num1[81];
char num2[81];
char num3[81];
max1=S[0];
max2=S[0];
max3=S[0];
puts ("\n\n ----------------------------------------------------");
puts (" | N Familiya I.O. N school Summa Mesto |");
puts (" ----------------------------------------------------");
while (fgets((char*)&tz,sizeof(olimpiada),f)!=NULL)
{ for (i=0,S[N]=0; i<N; i++)
S[N] += tz.ball[i]-'0';
tz.ball[NULL]='\0';
if (S[N] > max1)
{ max1=S[N];
strcpy(num1,tz.num);
}
else
{ if (S[N] > max2)
{ max2=S[N];
strcpy(num2,tz.num);
}
else
{ if (S[N] > max3)
{ max3=S[N];
strcpy(num3,tz.num);
}
}
}
}
printf(" %s %d 1 ",num1,max1);
printf("\n %s %d 2 ",num2,max2);
printf("\n %s %d 3 ",num3,max3);
fclose(f);
getch();
} |