Soluções da aula prática 11



1a.
PROGRAM EdgarAlanPoe;

Var f: text;
    c: char;
    ci: integer;
    cont: array[65..90] of integer;
    i: integer;

begin
  for i := 65 to 90 do cont[i] := 0;
  Assign(f, 'theraven.txt');
  Reset(f);
  While NOT Eof(f) do
    begin
      Read(f, c);
      c := UpCase(c);
      ci := Ord(c);
      if (ci>=65) AND (ci<=90) then
        cont[ci] := cont[ci] + 1;
    end;
  Close(f);
  for i := 65 to 90 do
    writeln(Chr(i),'  ',cont[i]);
end.

output (ecrã)

A  339
B  94
C  71
D  194
E  618
F  94
G  122
H  290
I  318
J  2
K  32
L  225
M  158
N  374
O  370
P  95
Q  9
R  336
S  278
T  437
U  121
V  66
W  79



1b.
PROGRAM EdgarAlanPoeF;

Var f: text;
    c: char;
    ci: integer;
    cont: array[65..90] of integer;
    i: integer;

begin
  for i := 65 to 90 do cont[i] := 0;
  Assign(f, 'theraven.txt');
  Reset(f);
  While NOT Eof(f) do
    begin
      Read(f, c);
      c := UpCase(c);
      ci := Ord(c);
      if (ci>=65) AND (ci<=90) then
        cont[ci] := cont[ci] + 1;
    end;
  Close(f);
  Assign(f,'contas.txt');
  Rewrite(f);
  for i := 65 to 90 do
    writeln(f, Chr(i), '  ', cont[i]);
  Close(f);
end.



1c.
PROGRAM EdgarAlanPoeC;

Var f: text;
    c: char;
    ci: integer;
    cont: array[65..90] of integer;
    i: integer;
    max: integer;
    maxi: integer;

begin
  for i := 65 to 90 do cont[i] := 0;
  Assign(f, 'theraven.txt');
  Reset(f);
  While NOT Eof(f) do
    begin
      Read(f, c);
      c := UpCase(c);
      ci := Ord(c);
      if (ci>=65) AND (ci<=90) then
        cont[ci] := cont[ci] + 1;
    end;
  Close(f);
  max := 0;
  for i := 65 to 90 do
    if cont[i]>max then
       begin
         max := cont[i];
         maxi := i;
       end;
  WriteLn('Max: ', Chr(maxi), '  ', cont[maxi]);
end.

output (ecrã)

Max: E  618