daily gadgets, computers, and electronic news
13/04
2005

#133: The Dole Queue

Sponsored Links

Berikut source code solusinya, dng menggunakan konsep circular array dan bahasa Pascal.

[pascal]
program uva(input,output);

uses crt;

const
infile = ”;
outfile = ”;

type tInt = longint;

const
max = 20;

var
dole : array [1..max] of byte;
n,m,k : integer;

procedure simulate;
var cw,ccw,i,left : integer;
begin
left:=n;
cw:=1; ccw:=n;
for i:=1 to n do dole[i]:=i;
repeat
i:=1;
while (i begin
cw:=cw+1;
if (cw>n) then cw:=1;
if (dole[cw]<>0) then i:=i+1;
end;
i:=1;
while (i begin
ccw:=(ccw-1) mod n;
if (ccw<1) then ccw:=n;
if (dole[ccw]<>0) then i:=i+1;
end;
if (cw=ccw) then
begin
left:=left-1;
write(output,dole[cw]:3);
if (left>0) then write(output,’,');
end
else
begin
left:=left-2;
write(output,dole[cw]:3,dole[ccw]:3);
if (left>0) then write(output,’,');
end;
dole[cw]:=0; dole[ccw]:=0;
if (left>0) then
begin
while (dole[cw]=0) do
begin
cw:=cw+1;
if (cw>n) then cw:=1;
end;
while (dole[ccw]=0) do
begin
ccw:=ccw-1;
if (ccw<1) then ccw:=n;
end;
end;
until (left=0);
writeln(output);
end;

begin
clrscr;
assign(input,infile); reset(input);
assign(output,outfile); rewrite(output);
while not eof(input) do
begin
readln(input,n,m,k);
if (n=0) and (m=0) and (k=0) then break;
simulate;
end;
close(output); assign(output,”); rewrite(output);
close(input); assign(input,”); reset(input);
end.
[/pascal]

NB:
1. Semoga gak bingung :)
2. Kalo bingung dan terus berlanjut, silahkan tanya :)

Pages: 1 2 3

#133: The Dole Queue is written by cosa and posted under Programming . If you like it, you might consider subscribing to our feed or receive our latest posts via email. Or else, you could also bookmark it to your favourite social bookmark sites. Further information about this article can be found .

No Comments (leave yours)

No comments yet.

Leave a comment