type //????????? ???????
queue=^students; //Students - ??? ???????? ???????, Queue - ??? ????????? ?? ???????
students=record
name,surname:string; //???? ???, ???????
course,math,phys,inf:integer; //???? ??????
next:queue; //????????? ?? ????????? ??????? ???????
end;
//??????? ??????? ??????????????? ??????
function Mid(var cur:queue):real;
begin
Mid:=(cur^.math + cur^.phys + cur^.inf)/3; //Cur - ????????? ?? ??????? ???????(?.?. ????????),
end; // ?????? ???????? ????? ??????????
//????????? ????? ????? ??? ????????? ???????
procedure input(var name, surname:string; var course, math, phys, inf:integer);
var str:string; //???? ??????????????? ? ??? ????? ????? ???????, ? ?????? str
begin
writeln('??????? ???????,???,???? (????? ???????)');
readln(str);
surname:=copy(str,1,pos(',',str)-1); //????????? ? ??????? ?????????? ?? ?????? ???????
delete(str,1,pos(',',str)); //??????? ?? ?????? str ??????? ? ?????? ???????
name:=copy(str,1,pos(',',str)-1); //?? ?? ????? ?????? ? ??????
delete(str,1,pos(',',str));
if pos(',',str)>0 then //????????? ??? ????? ????? ??? ?????????? ?? ???????,
course:=strtoint(copy(str,1,pos(',',str)-1)) // ???? ?????, ???? ?????? ?? ????? ??????
else if pos('.',str)>0 then
course:=strtoint(copy(str,1,pos('.',str)-1))
else
course:=strtoint(str);
//??? ?? ?? ????? ? ????????
writeln('??????? ?????? ?? ??????????,??????,??????????? (????? ???????)');
readln(str);
math:=strtoint(copy(str,1,pos(',',str)-1));
delete(str,1,pos(',',str));
phys:=strtoint(copy(str,1,pos(',',str)-1));
delete(str,1,pos(',',str));
if pos(',',str)>0 then
inf:=strtoint(copy(str,1,pos(',',str)-1))
else if pos('.',str)>0 then
inf:=strtoint(copy(str,1,pos('.',str)-1))
else
inf:=strtoint(str);
end;
//????????? ?????????? ? ???????. ?? ?????????? ???????, ??????? ??????????? ? ????? ??????
procedure Add(var head,tail:queue); //????? ??????? ??? ???? ?????? ????????? head ? tail
begin
if head=Nil then //???? ?????? ??????? ?????? ????
begin
new(head); //???????? ??? ???? ??????
tail:=head; // ????????? ?? ????????? ??????? ??? ?? ????????? ?? ??????(?.?. ?? ????)
end else
begin
new(tail^.next); //? ????????? ?????? ???????? ?????? ??? ????????? ????? ?????????? ???????
tail:=tail^.next; //?????? ????????? ??????? ? ???????? ?????????
end;
input(tail^.surname,tail^.name,tail^.course,
tail^.math,tail^.phys,tail^.inf); //????? ????????? input ?????????? ?????????? ? ????????? ???????
tail^.next:=Nil; //?????????? ???????? ???(??????? ????????? ???????? ?? Nil)
end;
// ????? ?????? ?????????
procedure Show(var head:queue);
var cur:queue; //Cur - ????????? ?? ?????? ???????
i:integer;
begin
i:=1; //??????? ?????????? ??????? ????????? ??????
cur:=head; //????? ?????????? ? ??????? ????????
while cur<>Nil do //???? ?????? ??????? ??????????
begin //??????? ??????????
writeln(inttostr(i)+'. '+cur^.name+' '+cur^.surname+', '+inttostr(cur^.course)+
' ????. ??????: '+inttostr(cur^.math)+', '+inttostr(cur^.phys)+', '+inttostr(cur^.inf)+'.');
cur:=cur^.next; //????????? ?? ???? ???????
i:=i+1; //???????? ???????
end;
end;
//????????? ????????, ?? ?????? ??????(?.?. ??? ??????? ???????? ? ????????)
//???????? ???? ? ?????? ???????, ?? ???????????
procedure Delete(var head:queue);
var temp:queue;
begin
temp:=head; //?????? ????????? ????????? ?? ?????? ???????
head:=head^.next; //?????? ?????? ????????? ???????? ????????(?????????? ??????)
dispose(temp); //??????? ?????? ??? ?????? ??????? ????? ????????? temp
end;
//?????????? ???????? ??????????
procedure Best(var head:queue);
var best,cur:queue;
begin
cur:=head; //???????? ????????? ? ??????? ????????
best:=cur; //?????????? ????????? ?? ??????? ????????? ?? ?????? ???????
while (cur <> Nil) do //???? ?????? ??????? ??????????
begin
if Mid(best) < Mid(cur) then //?????????? ?????? ???????(?? ?????? ??????) ? ???????
best:=cur; //???? ?????? ??????? ????? ?????? ???????, ?? ?????? ???????? ??????
cur:=cur^.next;
end; //??????? ?????????? ? ?????? ????????
writeln(best^.surname,' ',best^.name, ', ??????? ', best^.course, '-?? ????? ?????? ????? ?????????' );
end;
var
n:integer; //?????????? ?????? ????????
head,tail: queue; //????????? ?? ?????? ? ????? ???????
begin
n:=0;
while n>-1 do //??????? ?????????, N>-1(???? ???????????? ?? ?????? 4)
begin
writeln('???????:'+#10+'1. ????? ???????? ???????? ? ??????'+#10+
'2. ????? ??????? ??????'+#10+
'3. ??????? ??? ???????? ??????????? ????????'+#10+
'4. ????? ?? ?????????'+#10);
readln(n); //?????? ?????
if n=1 then Add(head,tail)
else if n=2 then Show(head)
else if n=3 then Best(head)
else if n=4 then n:=-1
end;
end.