找规律。参考了下以前的一个题目,Mars(或者是Martian,反正是火星人数数的那个)。列成一个表(长度为w的,boolean,相对应的字母有为true,无为false),然后从后向前找到一个空的。再从此向前找第一个一个非空的,把那个向后移1(肯定能保证后面那个不是true),然后让后面的true全部顶到移了的字母后。一个函数isend判断是否结束,一个过程next求下一个,一个过程print打印。program count(input,output);vars,t,w:integer;jam:array[1..26] of boolean;i,j:integer;a:char;procedure next;varii,jj,p:integer;beginp:=0;for ii:= t downto s do if not(jam[ii]) then break;for jj:= ii downto s do if jam[jj] then break;jam[jj]:=false;jam[jj+1]:=true;for ii:=(jj+2) to t do if jam[ii] then inc(p);for ii:=(jj+2) to t do jam[ii]:=false;for ii:=(jj+2) to (jj+1+p) do jam[ii]:=true;end;function isend:boolean;varii:integer;beginisend:=false;for ii:= t downto s do if not(jam[ii]) then break;if (s-ii)>=w then isend:=true;end;procedure print;varii:integer;beginfor ii:=s to t do if jam[ii] then write(chr(ord('a')+ii-1));writeln;end;beginassign(input,'count.in');assign(output,'count.out');reset(input);rewrite(output);readln(s,t,w);fillchar(jam,sizeof(jam),0);for i:=1 to w do beginread(a);jam[(ord(a)-ord('a')+1)]:=true;end;for i:=1 to 5 do if not(isend) then begin next; print; end;close(input);close(output);end.
|