主题:编程
wangjieni11
[专家分:0] 发布于 2007-10-16 20:25:00
三人对比赛名次进行预测:
甲说:A得第一,B得第三
乙说:C得第一,D得第四
丙说:D的第一,B得第三
每人说对了一半,请你排出A,B,C,D的名次
回复列表 (共14个回复)
沙发
moz [专家分:37620] 发布于 2007-10-16 23:37:00
CDBA
板凳
moz [专家分:37620] 发布于 2007-10-16 23:39:00
Dim jyb$(3)
jyb$(1) = "A B "
jyb$(2) = "C D"
jyb$(3) = "D B "
k$ = "ABCD"
Do
For i = 1 To 3
p = 0
For j = 1 To 4
If Mid$(k$, j, 1) = Mid$(jyb$(i), j, 1) Then p = p + 1
Next
If p <> 1 Then Exit For
Next
If i > 3 Then Print k$
k$ = nextpl$(k$)
Loop Until k$ = "ABCD"
End
Function nextpl$(a$)
l = Len(a$)
For e = (l - 1) To 1 Step -1
If Mid$(a$, e, 1) < Mid$(a$, e + 1, 1) Then Exit For
Next
If e > 0 Then
For i = l To (e + 1) Step -1
If Mid$(a$, i, 1) > Mid$(a$, e, 1) Then Exit For
Next
b$ = Mid$(a$, i, 1)
Mid$(a$, i, 1) = Mid$(a$, e, 1)
Mid$(a$, e, 1) = b$
End If
For i = (e + 1) To (l + e + 1) \ 2
j = l + e + 1 - i
b$ = Mid$(a$, i, 1)
Mid$(a$, i, 1) = Mid$(a$, j, 1)
Mid$(a$, j, 1) = b$
Next
nextpl$ = a$
End Function
3 楼
wx.psfx [专家分:10] 发布于 2007-10-17 14:13:00
2楼的程序太复杂
这一题可用穷举法
4 楼
moz [专家分:37620] 发布于 2007-10-17 14:37:00
嗯,你穷给我看看。
5 楼
wx.psfx [专家分:10] 发布于 2007-10-18 10:55:00
program ABCD;
var A,B,C,D:integer;
begin
for A:=1 to 4 do
for B:=1 to 4 do
if (A<>B) then
for C:=1 to 4 do
if (C<>B) and (B<>A) then
begin
D:=10-A-B-C;
if ((ord(A=1)+ord(B=3)=1) and (ord(C=1)+ord(D=4)=1) and (ord(D=1)+ord(B=3)=1)) then
write(A,B,C,D)
end;
end.
6 楼
wx.psfx [专家分:10] 发布于 2007-10-18 10:56:00
偶是一个小学生
7 楼
moz [专家分:37620] 发布于 2007-10-18 11:38:00
嗯,是你厉害,我连小学生都不如,我现在就去找一块豆腐.
8 楼
wx.psfx [专家分:10] 发布于 2007-10-18 14:15:00
我是刚开始学,还有很多题目不会做.希望各位老师能帮我解答
9 楼
强强 [专家分:4740] 发布于 2007-10-18 15:51:00
记住,不要轻易放弃自己的想法,写出来给他看看。
10 楼
hxy_anhui [专家分:320] 发布于 2009-01-29 19:51:00
CLS
FOR A = 1 TO 4
FOR B = 1 TO 4
FOR C = 1 TO 4
FOR D = 1 TO 4
IF A * B * C * D = 24 AND A + B + C + D = 10 THEN
IF (A = 1) + (B = 3) = -1 THEN
IF (C = 1) + (D = 4) = -1 THEN
IF (D = 1) + (B = 3) = -1 THEN
PRINT A; B; C; D
END IF
END IF
END IF
END IF
NEXT D
NEXT C
NEXT B
NEXT A
END
我来回复