ROCKS - Rocks Game
Tác giả: ladpro98
Ngôn ngữ: Pascal
program rocks;
uses math;
const maxN=15;
maxV=1 shl maxN;
fi='';
var f:array[1..maxN,0..maxV] of longint;
n:longint;
procedure input;
var f:text;
begin
assign(f,fi);
reset(f);
readln(f,n);
close(f);
end;
function getbit(n,i:longint):longint;
begin
exit((n shr (i-1)) and 1);
end;
procedure graycode;
var i,j:longint;
begin
f[1,1]:=0;
f[1,2]:=1;
for i:=2 to n do
for j:=1 to 1 shl i do
begin
if j<=(1 shl (i-1)) then
f[i,j]:=f[i-1,j]
else
f[i,j]:=f[i-1,(1 shl i)-j+1]+(1 shl (i-1));
end;
end;
procedure output;
var i,j:longint;
begin
for i:=1 to 1 shl n do
begin
for j:=1 to n do
if getbit(f[n,i],j)=1 then write('X')
else write('O');
writeln;
end;
for i:=1 to n do
write('O');
end;
begin
input;
graycode;
output;
end.