Pagini recente » Cod sursa (job #2590437) | Cod sursa (job #1522558) | Cod sursa (job #1400433) | Istoria paginii runda/2017simoji/clasament | Cod sursa (job #1765018)
program srtt;
var f,g:text;
i,j,x,y,n,m,aux,z:integer;
a:array[1..100] of integer;
ok:boolean;
begin
assign(f,'sortaret.in'); reset(f);
assign(g,'sortaret.out'); rewrite(g);
readln(f,n,m);
for i:=1 to n do a[i]:=i;
for i:=1 to m do
begin
readln(f,x,y);
z:=0;
for j:=1 to n do
begin
if a[j]=x then begin z:=1; break; end;
if a[j]=y then begin z:=2; break; end;
end;
if z=2 then begin
z:=j;
for j:=z to n do if a[j]=x then break;
for aux:=j downto z+1 do a[aux]:=a[aux-1];
a[z]:=x;
end;
end;
for i:=1 to n do write(g,a[i],' ');
close(f);
close(g);
end.