PersonalCorpus 版 (精华区)
149579 05:03:22 2 Mar 2002
Bozhang,HIT,P.R.China 1007 Pascal Accepted 0.17 sec 565K
var
sum,tot1,n,i,j,k:integer;
s:string;
begin
readln(n);
readln(s);
while (pos('0',s)<>0) or (pos('1',s)<>0) do begin
tot1:=0; sum:=0; for i:=1 to length(s) do if s[i]='1' then begin inc
(sum,i); inc(tot1) end;
if length(s)=n then begin
if sum mod (n+1) <> 0 then for i:=1 to length(s) do
if (s[i]='1') and ((sum-i) mod (n+1)=0) then begin
s[i]:='0'; break;
end;
writeln(s); readln(s);
continue;
end;
if length(s)>n then begin
k:=0;
for i:=1 to length(s) do begin
if s[i]='1' then j:=sum-(tot1-k-1)-i else j:=sum-(tot1-k);
if j mod (n+1)=0 then begin
delete(s,i,1);
break;
end;
if s[i]='1' then inc(k);
end;
writeln(s); readln(s); continue;
end;
if length(s)<n then begin
k:=0;
for i:=1 to length(s)+1 do begin
if (sum+(tot1-k)) mod (n+1)=0 then begin
insert('0',s,i);
break;
end;
if (sum+(tot1-k)+i) mod (n+1)=0 then begin
insert('1',s,i);
break;
end;
if s[i]='1' then inc(k);
end;
writeln(s);readln(s);
end;
end;
end.
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.019毫秒