ProgramEXP4 (input,output);
{12%}
const n=4;
typese=array[1..n*2] of char;
var i,j,i1,j1,k,s,t,s1,l,swap:integer;
temp
:char;
a
:se;
begin
fori:=1ton*2do read(a);readln;
s:=0;t:=0;
for i:=1 to n*2 do
if a='1' then s:=s+1
else if a='0' then t:=t+1;
if(sn)or(tn)thenwriteln('error')
elsebegin
s1:=0;
for i:=1 to 2*n-1doif aa[i+1] then s1:=s1+1;
writeln('jamp=',s1);swap:=0;
for i:=1 to 2*n-1 do
for j:=i+1 to 2*n do
if aa[j] then begin
temp:=a;a:=a[j] ;a[j]:=temp;
s:=0;
for l:=1 to 2*n-1 do
if a[l]a[l+1]thens:=s+1;
if s>swapthenbegin
swap:=s;i1:=i;j1:=j
end;
temp:=a; a:=a[j]; a[j]:=temp
end;
ifswap>0thenwriteln('maxswap=',swap-s1,' i=',i1,' j=',j1)
end
END.
输入:10101100 输出:
需要详细的讲解步骤。标准答案:jamp=5maxswap=2i=6j=7,可就是看不明白该程序的目的是干什么?
|