1.有一组数(设有N个),其排列顺序如下:3,6,11,45,23,70,67,34,26,89,90,15,56,50,20,10。编一程序交换这组数中任意指定的两段不重合数据。2.将1-9这就个数分成3组(每个数字只能使用一次),分别组成3个三位数,且这三个三位数的值构成1:2:3的比例,试求出所有满足条件的三个三位数。
參考答案:1.program a1;
const n=16;
const a:array[1..n] of integer =(3,6,11,45,23,70,67,26,89,90,15,56,50,20,10);
var i,k,b1,e1,b2,e2:integer;
var b:array[1..n] of integer;
begin
writeln('please read data:');
write('begin 1=');read(b1);
write('end 1=');read(e1);
write('begin 2=');read(b2);
write('end 2=');read(e2);
if b1<b2 then
begin
i:=b1;b1:=b2;b2:=i;
i:=e1;e1:=e2;e2:=i;
end;
for i:=1 to b1-1 do b[i]:=a[i];
for k:=0 to e2 -b2 do b[b1+k]:=a[b2+k];
for k:=1 to b2 -e1-1 do b[b1+e2-b2+k]:=a[e1+k];
for k:=0 to e1-b1 do b[e2-e1+b1+k]:=a[b1+k];
for i:=e2+1 to n do b[i]:=a[i];
writeln('number:':7,'begin:':7,'end:':7);
end.
2.program a2;
var a:array[0..9] of integer;
i,g,s,b,k,t:integer;
begin
writeln('result');
for i:=100 to 333 do
begin
for k:=0 to 9 do a[k]:=0;
k:=i;
g:=k mod 10;
b:=k div 100;
s:=(k div 10) mod 10;
a[g]:=1;a[s]:=1;a[b]:=1;
k:=2*i;
g:=k mod 10;b:=k div 100;s:=(k div 10) mod 10;
a[g]:=1;a[s]:=1;a[b]:=1;
k:=3*i;
g:=k mod 10;b:=k div 100;s:=(k div 10) mod 10;
a[g]:=1;a[s]:=1;a[b]:=1;
t:=0;
for k:=1 to 9 do
t:=t+a[k];
if t=9 then writeln(i:4,i*2:4,i*3:4);
end;
end.