program soalUAS;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
filestr: text;
a: array [1..100] of string ;
jumlaha: array [1..100] of integer;
ketemu,poschar,p: integer;
zs,huruf: string;
awalspasi: boolean;
i,j:integer;
nilaicari:string;
z,x:string;
begin
{ TODO -oUser -cConsole Main : Insert code here }
assign (filestr,'c:/data/input.txt');
reset (filestr);
while not eof(filestr) do
begin
readln (filestr, x);
writeln (x);
end;
close (filestr);
writeln;
awalspasi:= false;
p:= length (x);
poschar:= 1;
while poschar <= p do
begin
huruf:= copy (x, poschar, 1);
if huruf=' ' then zs:= ''
else
if huruf='/' then
if awalspasi = false then
begin
z:= zs;
awalspasi:= true;
end
else z:= z + ' '+ zs
else
zs:=zs +huruf;
poschar:=poschar+1;
end;
writeln (z);
assign (filestr,'c:/data/output.txt');
rewrite (filestr);
writeln(filestr, z);
close (filestr);
writeln;
p:= length (z);
poschar:= 2;
i:=2;
huruf:= copy (z, 1, 1);
a[1]:= huruf;
jumlaha[1]:= 1;
while poschar <=p do
begin
huruf:= copy (z, poschar, 1); {poschar +1}
nilaicari:= huruf;
j:=i-1;
ketemu:=0;
repeat
begin
if nilaicari = a[j] then
begin
jumlaha[j]:= jumlaha[j]+1;
ketemu:=1;
end;
j:=j-1;
end;
until ((ketemu=1) or (j=0)) ;
if ketemu=0 then
begin
a[i]:= nilaicari;
jumlaha[i]:= 1;
i:= i+1;
end;
poschar:= poschar +1;
end;
for j:= 1 to i-1 do
writeln (a[j],' ',jumlaha[j]);
readln;
end.
{$APPTYPE CONSOLE}
uses
SysUtils;
var
filestr: text;
a: array [1..100] of string ;
jumlaha: array [1..100] of integer;
ketemu,poschar,p: integer;
zs,huruf: string;
awalspasi: boolean;
i,j:integer;
nilaicari:string;
z,x:string;
begin
{ TODO -oUser -cConsole Main : Insert code here }
assign (filestr,'c:/data/input.txt');
reset (filestr);
while not eof(filestr) do
begin
readln (filestr, x);
writeln (x);
end;
close (filestr);
writeln;
awalspasi:= false;
p:= length (x);
poschar:= 1;
while poschar <= p do
begin
huruf:= copy (x, poschar, 1);
if huruf=' ' then zs:= ''
else
if huruf='/' then
if awalspasi = false then
begin
z:= zs;
awalspasi:= true;
end
else z:= z + ' '+ zs
else
zs:=zs +huruf;
poschar:=poschar+1;
end;
writeln (z);
assign (filestr,'c:/data/output.txt');
rewrite (filestr);
writeln(filestr, z);
close (filestr);
writeln;
p:= length (z);
poschar:= 2;
i:=2;
huruf:= copy (z, 1, 1);
a[1]:= huruf;
jumlaha[1]:= 1;
while poschar <=p do
begin
huruf:= copy (z, poschar, 1); {poschar +1}
nilaicari:= huruf;
j:=i-1;
ketemu:=0;
repeat
begin
if nilaicari = a[j] then
begin
jumlaha[j]:= jumlaha[j]+1;
ketemu:=1;
end;
j:=j-1;
end;
until ((ketemu=1) or (j=0)) ;
if ketemu=0 then
begin
a[i]:= nilaicari;
jumlaha[i]:= 1;
i:= i+1;
end;
poschar:= poschar +1;
end;
for j:= 1 to i-1 do
writeln (a[j],' ',jumlaha[j]);
readln;
end.
Tidak ada komentar:
Posting Komentar