黑白棋子的移动(normal) ssl 1310

版权声明:转载者乖乖♂站好 https://blog.csdn.net/Eric1561759334/article/details/53765217

这道题本质上是递归

n=7
step 0:ooooooo*******–
step 1:oooooo–*****o
step 2:oooooo******–o*
step 3:ooooo–****o*o
step 4:ooooo*****–o*o*
step 5:oooo–***o*o*o
step 6:oooo****–o*o*o*
step 7:ooo–**o*o*o*o
step 8:ooo*o**–o*o*o
step 9:o–o**oo*o*o*o
step 10:o*o*o*–o*o*o*o*
step 11:–o*o*o*o*o*o*o*

从这可以看出,先把n=7变成n=6,再把n=6变成n=5,以此类推。
代码如下:

var n,io,i,ans:longint;
    a:array[1..100] of char;
procedure print;
var i:longint;
begin
  write('step',ans:2,':');
  for i:=1 to io do write(a[i]);
  writeln;
  inc(ans);
end;
procedure move(m1,m2:longint);
var t:char;
begin
  t:=a[m1];a[m1]:=a[m2];a[m2]:=t;
end;
begin
  readln(n); io:=n*2+2;
  for i:=1 to n do a[i]:='o';
  for i:=n+1 to 2*n do a[i]:='*';
  a[2*n+1]:='-';a[2*n+2]:='-'; print;
  while n>4 do
  begin
    move(n,2*n+1);move(n+1,2*n+2);print;
    move(2*n-1,n);move(2*n,n+1);print;
    dec(n);
  end;
  move(n,2*n+1);move(n+1,2*n+2);print;
  move(2*n,n);move(2*n+1,n+1);print;
  move(2,2*n);move(3,2*n+1);print;
  move(2*n-1,2);move(2*n,3);print;
  move(1,2*n-1);move(2,2*n);print;
end.
展开阅读全文

没有更多推荐了,返回首页