-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject2.bak
92 lines (74 loc) · 1.64 KB
/
project2.bak
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
program project2;
uses
classes, sysutils,StrUtils;
procedure bsort(var lista: array of longint);
var n, i,temp: longint;
begin
n:=length(lista)-1;
while n>0 do
begin
for i:=0 to n-2 do
begin
if lista[i]<lista[i+1] then
begin
temp:= lista[i];
lista[i]:=lista[i+1];
lista[i+1]:=temp;
end;
end;
n:=n-1;
end;
end;
var i, j,numero, erro:longint;
arquivo: textfile;
lista: array of longint;
linha:string;
caracter:char;
maior, nummaior:longint;
maior2, maior3, nummaior2, nummaior3, total:longint;
begin
i:=0;
Assign(arquivo,'entrada.txt');
reset (arquivo);
while not eof(arquivo) do
begin
setlength (lista,i+1);
readln(arquivo,linha );
val (linha, numero, erro);
if erro=0 then
begin
lista[i]:=lista[i] + numero;
end
else
begin
if lista[i] <> 0 then
i:=i+1;
end;
end;
maior:=0;
maior2:=0;
maior3:=0;
for j:=0 to length(lista)-1 do
begin
if nummaior<lista[j] then
begin
nummaior:= lista[j];
maior:=j;
end
else
if nummaior2<lista[j] then
begin
nummaior2:= lista[j];
maior2:=j;
end
else
if nummaior3 < lista[j] then
begin
nummaior3:= lista[j];
maior3:=j;
end;
writeln ('Elfo numero ',j+1,' possui ',lista[j]);
end;
bsort(lista);
writeln ('Os maiors Elfos ',lista[0], ' ',lista[1],' ',lista[2]);
end.