✔ 最佳答案
個遊戲應該叫 mastermind, 唔係 bingo
我個版本係 Irie pascal, not free pascal, 你可以試試再修改下
同埋個遊戲好多假設,你可以再執執
program mastermind(output);
var
a : array[1..5] of integer;
b : array[1..5] of integer;
i,j : integer;
TypeA, TypeB : integer;
repeated : boolean;
guess : real;
start : integer;
begin
randomize;
for i := 1 to 5 do
repeat
repeated := false;
a[i] := trunc(random*10);
for j := 1 to i-1 do
if a[i] = a[j] then
repeated := true;
until NOT (repeated);
repeat
write("Please input a five digits number (99999 - quit): ");
readln(guess);
if guess > 99999 then
writeln("number out of range")
else if guess <> 99999 then
begin
start := 10000;
for i := 1 to 5 do
begin
b[i] := trunc(guess) div start;
guess := guess - b[i] * start;
start := start div 10;
end;
TypeA := 0;
TypeB := 0;
for i := 1 to 5 do
begin
if a[i] = b[i] then TypeA := TypeA + 1;
for j := 1 to 5 do
begin
if (a[i] = b[j]) and (i <> j) then TypeB := TypeB + 1;
end;
end;
if TypeA <> 5 then
for i := 1 to TypeA do write('A');
for i := 1 to TypeB do write('B');
for i := 1 to (5-TypeA-TypeB) do write('-');
writeln;
end;
until (TypeA = 5) or (guess = 99999);
for i := 1 to 5 do
begin
write(a[i]);
end;
writeln;
for i := 1 to 5 do
begin
write(b[i]);
end;
end.
2007-12-19 02:14:49 補充:
頭先無為意,我將 A 同 B 個意思倒轉左,請自行修改