第四届奥赛程序阅读帮助:

[复制链接]
查看11 | 回复2 | 2010-8-10 13:13:10 | 显示全部楼层 |阅读模式
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,可就是看不明白该程序的目的是干什么?

回复

使用道具 举报

千问 | 2010-8-10 13:13:10 | 显示全部楼层
自己已解决!
回复

使用道具 举报

千问 | 2010-8-10 13:13:10 | 显示全部楼层
查一下高一电脑必修二课本
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行