не так уж и трудно, если
program project2;
var
n,a,b,c,i,k,max,min: longint;
inp,outp: text;
begin
assign(inp,'input.txt');
reset(inp);
assign(outp,'output.txt');
rewrite(outp);
readln(inp,n);
max: =0;
min: =0;
c: =0;
for i: =1 to n do
read(f1,a);
if i=1 then
b: =a;
if a> max then
max: =a;
k: =a-c;
c: =a;
if k< 0 then
k: =abs(k);
min: =min+k;
if k> min then
min: =k;
end;
max: =max-b;
write(outp,max,' ',min);
close(inp);
close(outp);
end.
PascalABC.NET 3.5.1
program D_contest;
type
TStat = record
nick: string;
wins, battles: integer;
proc: real;
N, i, num: integer;
str: array of string;
stat: array of TStat;
function found(ni_ck: string): integer;
found := -1;
for var e := 0 to Length(stat) - 1 do
if stat[e].nick = ni_ck then
found := e;
break;
v_pts, e_pts, l_e: integer;
F: textfile;
k: real;
s: string;
Assign(F, 'input.txt');
Reset(F);
readln(F, n);
SetLength(str, n);
SetLength(stat, 1);
for i := 0 to n - 1 do
readln(F, str[i]);
//get enemy_nick
nick := Copy(str[i], 1, Pos(' ', str[i]) - 1);
Delete(str[i], 1, Pos(' ', str[i]));
if (stat[0].nick <> '') then
num := found(nick);
if (num = -1) then //not found
l_e := Length(stat);
SetLength(stat, l_e + 1);
num := l_e;
stat[num].nick := nick;
end
else
stat[0].nick := nick;
stat[num].battles += 1;
//get Vania_points
v_pts := StrToInt(Copy(str[i], 1, Pos(' ', str[i])));
//get enemy_points
e_pts := StrToInt(str[i]);
if v_pts > e_pts Then
stat[num].wins += 1;
Close(F);
//вычисляю процент побед
for i := 0 to Length(stat) - 1 do
stat[i].proc := stat[i].wins / stat[i].battles;
//сортировка по процентам
for i := 0 to Length(stat) - 2 do
for var j := 0 to Length(stat) - i - 2 do
if stat[j].proc > stat[j + 1].proc then
k := stat[j].proc;
stat[j].proc := stat[j + 1].proc;
stat[j + 1].proc := k;
s := stat[j].nick;
stat[j].nick := stat[j + 1].nick;
stat[j + 1].nick := s;
//сортировка по алфавиту
if (stat[j].proc = stat[j + 1].proc) and (stat[j].nick > stat[j + 1].nick) then
writeln(Length(stat));
write(stat[i].nick, ' ');
writeln(stat[i].proc * 100:0:6);
Объяснение:
Смотри код
не так уж и трудно, если
program project2;
var
n,a,b,c,i,k,max,min: longint;
inp,outp: text;
begin
assign(inp,'input.txt');
reset(inp);
assign(outp,'output.txt');
rewrite(outp);
readln(inp,n);
max: =0;
min: =0;
c: =0;
for i: =1 to n do
begin
read(f1,a);
if i=1 then
b: =a;
if a> max then
max: =a;
k: =a-c;
c: =a;
if k< 0 then
begin
k: =abs(k);
min: =min+k;
if k> min then
min: =k;
end;
end;
max: =max-b;
write(outp,max,' ',min);
close(inp);
close(outp);
end.
PascalABC.NET 3.5.1
program D_contest;
type
TStat = record
nick: string;
wins, battles: integer;
proc: real;
end;
var
N, i, num: integer;
str: array of string;
stat: array of TStat;
nick: string;
function found(ni_ck: string): integer;
begin
found := -1;
for var e := 0 to Length(stat) - 1 do
begin
if stat[e].nick = ni_ck then
begin
found := e;
break;
end;
end;
end;
var
v_pts, e_pts, l_e: integer;
F: textfile;
k: real;
s: string;
begin
Assign(F, 'input.txt');
Reset(F);
readln(F, n);
SetLength(str, n);
SetLength(stat, 1);
for i := 0 to n - 1 do
begin
readln(F, str[i]);
//get enemy_nick
nick := Copy(str[i], 1, Pos(' ', str[i]) - 1);
Delete(str[i], 1, Pos(' ', str[i]));
if (stat[0].nick <> '') then
begin
num := found(nick);
if (num = -1) then //not found
begin
l_e := Length(stat);
SetLength(stat, l_e + 1);
num := l_e;
stat[num].nick := nick;
end;
end
else
begin
stat[0].nick := nick;
end;
stat[num].battles += 1;
//get Vania_points
v_pts := StrToInt(Copy(str[i], 1, Pos(' ', str[i])));
Delete(str[i], 1, Pos(' ', str[i]));
//get enemy_points
e_pts := StrToInt(str[i]);
if v_pts > e_pts Then
stat[num].wins += 1;
end;
Close(F);
//вычисляю процент побед
for i := 0 to Length(stat) - 1 do
begin
stat[i].proc := stat[i].wins / stat[i].battles;
end;
//сортировка по процентам
for i := 0 to Length(stat) - 2 do
begin
for var j := 0 to Length(stat) - i - 2 do
begin
if stat[j].proc > stat[j + 1].proc then
begin
k := stat[j].proc;
stat[j].proc := stat[j + 1].proc;
stat[j + 1].proc := k;
s := stat[j].nick;
stat[j].nick := stat[j + 1].nick;
stat[j + 1].nick := s;
end;
end;
end;
//сортировка по алфавиту
for i := 0 to Length(stat) - 2 do
begin
for var j := 0 to Length(stat) - i - 2 do
begin
if (stat[j].proc = stat[j + 1].proc) and (stat[j].nick > stat[j + 1].nick) then
begin
k := stat[j].proc;
stat[j].proc := stat[j + 1].proc;
stat[j + 1].proc := k;
s := stat[j].nick;
stat[j].nick := stat[j + 1].nick;
stat[j + 1].nick := s;
end;
end;
end;
writeln(Length(stat));
for i := 0 to Length(stat) - 1 do
begin
write(stat[i].nick, ' ');
writeln(stat[i].proc * 100:0:6);
end;
end.
Объяснение:
Смотри код