blob: 76f232347c8c52300e63761f8b3d2ab6e436121a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
unit dic;
interface
function count_char(c: char): longint;
function get_char_at_pos(x: longint): char;
procedure answer(s: string);
implementation
var
secret_word: string;
words: array [1..1000000] of string;
total_cost, n: longint;
procedure answer(s: string);
begin
if s = secret_word then
begin
writeln('Chuc mung ban da tim ra dap an chinh xac la "', s, '"');
writeln('Chi phi ban da su dung la ', total_cost);
end
else
begin
writeln('Dap an ban dua ra la "', s, '"');
writeln('Dap an chinh xac la "', secret_word, '"');
end;
halt;
end;
procedure cost_limit_exceed;
begin
writeln('Chi phi ban da su dung vuot qua chi phi toi da cho phep');
halt;
end;
function count_char(c: char): longint;
var
i, res: longint;
begin
total_cost := total_cost + 1;
if (total_cost > 1000) then
cost_limit_exceed;
res := 0;
for i := 1 to length(secret_word) do
if secret_word[i] = c then
inc(res);
exit(res);
end;
function get_char_at_pos(x: longint): char;
begin
total_cost := total_cost + 10;
if (total_cost > 1000) then
cost_limit_exceed;
if (x < 1) or (x > length(secret_word)) then
exit('#');
exit(secret_word[x]);
end;
procedure check_secret_word;
var
f: text;
i: longint;
ok: boolean;
begin
assign(f, 'dic.dat');
reset(f);
while not seekeof(f) do
begin
inc(n);
readln(f, words[n]);
end;
close(f);
ok := false;
for i := 1 to n do
if words[i] = secret_word then ok := true;
if not ok then
begin
writeln('Du lieu duoc khoi tao khong chinh xac. Dap an can tim khong nam trong tu dien');
halt;
end;
end;
procedure init;
begin
writeln;
writeln(' TU DIEN ');
writeln('*****************');
writeln;
secret_word := 'cat';
total_cost := 0;
check_secret_word;
end;
initialization
init;
end.
|