var
a,b,c: array [0..100] of string;
filestr: text;
o,x,p,h,q,i,j,n:integer;
nbaris, poschar: integer;
cs,bs,k,temp: string ;
spasi: boolean;
begin
{ TODO -oUser -cConsole Main : Insert code here }
{algoritma baca teks soal}
assign (filestr,'c:/data/nimsaudarainput.txt');
reset (filestr);
nbaris:=0;
while not eof(filestr) do
begin
readln (filestr, a[nbaris]);
writeln (a[nbaris]);
nbaris:=nbaris+1;
end;
close (filestr);
{algoritma mengolah teks menjadi frasa kata}
for x:= 0 to nbaris-2 do
begin
spasi:= false;
p:= length (a[x]);
poschar:= 1;
while poschar < p do
begin
k:= copy (a[x], poschar, 1);
if k=' ' then bs:= ''
else
if k='/' then
if spasi=false then
begin
b[x]:= bs;
spasi:=true;
end
else b[x]:= b[x] + ' '+ bs
else
bs:=bs +k;
poschar:=poschar+1;
end;
writeln (b[x]);
end;
{algoritma menyimpan frasa kata ke array b}
assign (filestr,'c:/data/nimsaudaraoutput1.txt');
rewrite (filestr);
for x:=0 to nbaris do
begin
writeln(filestr, b[x]);
end;
close (filestr);
{algoritma menyimpan kata ke array c}
q:=0;
for x:= 0 to nbaris-2 do
begin
p:= length (b[x]);
poschar:= 1;
while poschar <= p do
begin
k:= copy (b[x], poschar, 1);
if k=' ' then
begin
c[q]:=cs;
cs:='';
q:=q+1
end
else
begin
cs:= cs+k;
c[q]:=cs;
end;
poschar:=poschar+1;
end;
c[q]:=cs;
q:=q+1;
cs:='';
end;
{algoritma membaca array c}
for x:= 0 to q-1 do
writeln ('c[',x,']: ', c[x]);
writeln;
{algoritma mengurut kata di array c}
for i:= 2 to q do
for j:= 1 to q-i do
if c[j]> c[j+1] then
begin
temp:= c[j+1];
c[j+1]:= c[j];
c[j]:=temp;
end;
{algoritma membaca array c setelah diurutkan}
for x:= 0 to q-1 do
begin
writeln ('c[',x,']: ', c[x]);
end;
readln;
end.
a,b,c: array [0..100] of string;
filestr: text;
o,x,p,h,q,i,j,n:integer;
nbaris, poschar: integer;
cs,bs,k,temp: string ;
spasi: boolean;
begin
{ TODO -oUser -cConsole Main : Insert code here }
{algoritma baca teks soal}
assign (filestr,'c:/data/nimsaudarainput.txt');
reset (filestr);
nbaris:=0;
while not eof(filestr) do
begin
readln (filestr, a[nbaris]);
writeln (a[nbaris]);
nbaris:=nbaris+1;
end;
close (filestr);
{algoritma mengolah teks menjadi frasa kata}
for x:= 0 to nbaris-2 do
begin
spasi:= false;
p:= length (a[x]);
poschar:= 1;
while poschar < p do
begin
k:= copy (a[x], poschar, 1);
if k=' ' then bs:= ''
else
if k='/' then
if spasi=false then
begin
b[x]:= bs;
spasi:=true;
end
else b[x]:= b[x] + ' '+ bs
else
bs:=bs +k;
poschar:=poschar+1;
end;
writeln (b[x]);
end;
{algoritma menyimpan frasa kata ke array b}
assign (filestr,'c:/data/nimsaudaraoutput1.txt');
rewrite (filestr);
for x:=0 to nbaris do
begin
writeln(filestr, b[x]);
end;
close (filestr);
{algoritma menyimpan kata ke array c}
q:=0;
for x:= 0 to nbaris-2 do
begin
p:= length (b[x]);
poschar:= 1;
while poschar <= p do
begin
k:= copy (b[x], poschar, 1);
if k=' ' then
begin
c[q]:=cs;
cs:='';
q:=q+1
end
else
begin
cs:= cs+k;
c[q]:=cs;
end;
poschar:=poschar+1;
end;
c[q]:=cs;
q:=q+1;
cs:='';
end;
{algoritma membaca array c}
for x:= 0 to q-1 do
writeln ('c[',x,']: ', c[x]);
writeln;
{algoritma mengurut kata di array c}
for i:= 2 to q do
for j:= 1 to q-i do
if c[j]> c[j+1] then
begin
temp:= c[j+1];
c[j+1]:= c[j];
c[j]:=temp;
end;
{algoritma membaca array c setelah diurutkan}
for x:= 0 to q-1 do
begin
writeln ('c[',x,']: ', c[x]);
end;
readln;
end.
izin copas yee wkwk
BalasHapussikattt
BalasHapus