分析:
有规律可寻。
const maxn=1000; var b:array[1..maxn]of char; sp,i,n,num:longint; procedure print; var i:longint; begin inc(num); write('step ',num,':'); for i:=1 to 2*(n+1) do write(b[i]); writeln; end; procedure move(k:longint); var i:longint; begin for i:=0 to 1 do begin b[sp+i]:=b[k+i];b[k+i]:='_'; end; sp:=k; print; end; procedure mv(n:longint); begin if n=4 then begin move(4); move(8); move(2); move(7); move(1); end else begin move(n); move(2*n-1); mv(n-1); end; end; begin readln(n); for i:=1 to n do b[i]:='O'; for i:=n+1 to 2*n do b[i]:='*'; b[i+1]:='_'; b[i+2]:='_'; sp:=2*n+1; num:=-1; print; mv(n); end.
#include<cstring> #include<cstdio> #include<iostream> using namespace std; string s,ans; int n; int main() { cin>>n; s=""; for (int i=0;i<n;i++) s+='O'; for (int i=0;i<n;i++) s+='*'; s+="__"; int x=n,tot=0; cout<<"step "<<tot<<":"<<s<<endl; tot++; while (x>4) { s[x-1]='_'; s[x]='_'; s[2*x]='O'; s[2*x+1]='*'; cout<<"step "<<tot<<":"<<s<<endl; tot++; s[2*x-1]='_'; s[2*x-2]='_'; s[x-1]='*'; s[x]='*'; cout<<"step "<<tot<<":"<<s<<endl; x--; tot++; } ans=s.substr(10,(n-4)*2); cout<<"step "<<tot<<":"<<"OOO__***O*"+ans<<endl; tot++; cout<<"step "<<tot<<":"<<"OOO*O**__*"+ans<<endl; tot++; cout<<"step "<<tot<<":"<<"O__*O**OO*"+ans<<endl; tot++; cout<<"step "<<tot<<":"<<"O*O*O*__O*"+ans<<endl; tot++; cout<<"step "<<tot<<":"<<"__O*O*O*O*"+ans<<endl; tot++; return 0; }
var s,ans:string; n,total,i,x:longint; begin readln(n); for i:=1 to n do s:=s + 'O'; for i:=1 to n do s:=s + '*'; s:=s + '__'; x:=n; writeln('step ',total,':',s); inc(total); while x > 4 do begin s[x]:='_'; s[x+1]:='_'; s[2*x+1]:='O'; s[2*x+2]:='*'; writeln('step ',total,':',s); inc(total); s[2*x]:='_'; s[2*x-1]:='_'; s[x]:='*'; s[x+1]:='*'; dec(x); writeln('step ',total,':',s); inc(total); end; ans:=copy(s,11,(n-4)*2); writeln('step ',total,':OOO__***O*'+ans); inc(total); writeln('step ',total,':OOO*O**__*'+ans); inc(total); writeln('step ',total,':O__*O**OO*'+ans); inc(total); writeln('step ',total,':O*O*O*__O*'+ans); inc(total); writeln('step ',total,':__O*O*O*O*'+ans); inc(total); end.
转载于:https://www.cnblogs.com/qilinart/articles/4963291.html