Algorithm 版 (精华区)
发信人: sino (蚱蜢舟), 信区: Algorithm
标 题: Re: shining提供的逻辑题
发信站: 哈工大紫丁香 (2002年01月23日20:12:02 星期三), 站内信件
只有一组解:c,d,e,b,e,e,d,c,b,a
程序:
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
a:array[1..10] of integer;
a1,a2,a3,a4,a5,a6,a7,a8,a9,a10:integer;
c:array[1..5] of char;
function check1:boolean;
var i,j,k:integer;
begin
j:=0; k:=0;
for i:=2 to 6 do if a[i]=2 then begin
inc(j); k:=i;
end;
if (j=1) and (k-1=a[1]) then Result:=true else Result:=false;
end;
function check2:boolean;
var i,j,k:integer;
begin
j:=0; k:=0;
for i:=2 to 6 do if a[i]=a[i+1] then begin
inc(j); k:=i;
end;
if (j=1) and (k-1=a[2]) then Result:=true else Result:=false;
end;
function check3:boolean;
var i,j,k:integer;
begin
k:=0;
if (a[3]=1) and (a[1]=1) then inc(k);
if (a[3]=2) and (a[2]=2) then inc(k);
if (a[3]=3) and (a[4]=3) then inc(k);
if (a[3]=4) and (a[7]=4) then inc(k);
if (a[3]=5) and (a[6]=5) then inc(k);
if k=1 then Result:=true else Result:=false;
end;
function check4:boolean;
var i,j,k:integer;
begin
j:=0; for i:=1 to 10 do if a[i]=1 then inc(j);
if j=a[4]-1 then Result:=true else Result:=false;
end;
function check5:boolean;
var i,j,k:integer;
begin
j:=0; k:=0;
for i:=6 to 10 do if a[i]=a[5] then begin
inc(j); k:=i;
end;
if (j=1) and (a[5]=11-k) then Result:=true else Result:=false;
end;
function check6:boolean;
var i,j,k:integer;
c:array[1..5] of integer;
begin
fillchar(c,sizeof(c),0);
for i:=1 to 10 do inc(c[a[i]]);
j:=0; k:=0;
for i:=2 to 5 do if c[i]=c[1] then begin
inc(j); k:=i;
end;
if ((j<>1) and (a[6]=5)) or ((j=1) and (a[6]=k-1)) then Result:=true els
e Result:=false;
end;
function check7:boolean;
var i,j,k:integer;
begin
i:=abs(a[7]-a[8]);
if i+a[7]=5 then Result:=true else Result:=false;
end;
function check8:boolean;
var i,j,k:integer;
begin
j:=0;
for i:=1 to 10 do if a[i] in [1,5] then inc(j);
if j-1 = a[8] then Result:=true else Result:=false;
end;
function check9:boolean;
var i,j,k:integer;
begin
j:=0;
for i:=1 to 10 do if a[i] in [2,3,4] then inc(j);
if ((a[9]=1) and (j in [3,7])) or
((a[9]=2) and (j=6)) or
((a[9]=3) and (j in [4,9])) or
((a[9]=4) and (j=8)) then
Result:=true else Result:=false;
end;
function check10:boolean;
var i,j,k:integer;
begin
Result:=true;
end;
begin {Main}
c[1]:='a'; c[2]:='b'; c[3]:='c'; c[4]:='d'; c[5]:='e';
for a1:=1 to 5 do for a2:=1 to 5 do for a3:=1 to 5 do for a4:=1 to 5 do
for a5:=1 to 5 do for a6:=1 to 5 do for a7:=1 to 5 do for a8:=1 to 5 do
for a9:=1 to 5 do for a10:=1 to 5 do begin
a[1]:=a1; a[2]:=a2; a[3]:=a3; a[4]:=a4; a[5]:=a5;
a[6]:=a6; a[7]:=a7; a[8]:=a8; a[9]:=a9; a[10]:=a10;
if check1 and check2 and check3 and check4 and check5 and check6 and
check7 and check8 and check9 and check10 then
writeln(c[a1],' ',c[a2],' ',c[a3],' ',c[a4],' ',c[a5],' ',
c[a6],' ',c[a7],' ',c[a8],' ',c[a9],' ',c[a10]);
end;
writeln('Fin'); readln;
end.
--
我一直认为马佩军是西电编程第一高手,他编程的时候根本不是人,是指针。
--《阳光男孩之大学十年》
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: mtlab4.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.183毫秒