初一的学生跪求高手们解一道PASCAL的问题,

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:12:26
一次考试后, 分获数学, 物理, 化学, 和外语第一名的考生一起猜测考试结果.

甲说: 丁获得外语第一.

乙说: 丙会获得物理第一.

丙说: 甲的数学成绩不会超过第三名.

丁说: 没有人的化学成绩能超过乙.

公布结果后发现: 只有获得数学, 外语第一的两人猜对了. 请编程求出他们各获哪科

第一.

var a,b,c,d,e,f,g,h,i,j,k,m,n:longint;
begin
for a:=1 to 4 do
for b:=1 to 4 do
for c:=1 to 4 do
for d:=1 to 4 do
if (a*b*c*d=24)and((a=1)or(b=1)or(c=1)or(d=1))(判断有无重复) then
begin
if ord(d=4)=1 then if (a<>1)or(b<>2) then continue;
if ord(b=3)=1 then if (a<>2)and(d<>2) then continue;
if ord(a<>1)=1 then if (a<>3)and(d<>3)then continue;
if ord(c=2)=1 then if (a<>4)and(d<>4) then continue;(对条件进行判断)
if ord(d=4)+ord(b=3)+ord(a<>1)+ord(c=2)<>2 then continue;(总共只有两个人对)
writeln(a,b,c,d);
end;
end.

逻辑判断题,答案是错不了的,步骤你检验一下吧
说明一下,a,b,c,d分别是数学,物理,化学,外语第一名的编号,甲是1,乙是2,丙是3,丁是4