不是VIP会员,不能显示答案

题目解答

题目:
Program EXP4 (input,output); {12%}
const n=4;
type se=array[1..n*2] of char;
var i,j,i1,j1,k,s,t,s1,l,swap:integer;
temp :char;
a :se;
begin
for i:=1 to n*2 do read(a[i]); readln;
s:=0; t:=0;
for i:=1 to n*2 do
if a[i]='1' then s:=s+1
else if a[i]='0' then t:=t+1;
if (s<>n) or (t<>n) then writeln('error')
else begin
s1:=0;
for i:=1 to 2*n-1 do if a[i]<>a[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 a[i]<>a[j] then begin
temp:=a[i];a[i]:=a[j] ;a[j]:=temp;
s:=0;
for l:=1 to 2*n-1 do
if a[l]<>a[l+1] then s:=s+1;
if s>swap then begin
swap:=s; i1:=i; j1:=j
end;
temp:=a[i]; a[i]:=a[j]; a[j]:=temp
end;
if swap>0 then writeln('maxswap=',swap-s1,' i=',i1,' j=',j1)
end
END.
输入:10101100
输出:jamp=5 maxswap=2 i=6 j=7
考点:
分析:
解答:
评论:
老师: