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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
| program ExperementsWithSearching;
const
CorrectSymbols = ['A'..'Z', 'a'..'z', 'А'..'Я', 'а'..'я', 'ё', 'Ё', '0'..'9'];
type
tPtr = ^tNode;
tNode = record
count : integer;
key : string;
left, right : tPtr;
end;
tTree = tPtr;
procedure Search(var T: tTree; var K: string; var Res: tPtr);
var
Quit: boolean;
begin
Quit := false;
repeat
if T = nil then
Quit := true
else if K < T^.Key then
T := T^.left
else if K > T^.Key then
T := T^.right
else
Quit := true;
until Quit;
Res := T;
end;
procedure AssignFiles(Names : string; dict, inp, outp : text);
var
i : Integer;
dictName, inpName, OutpName : string;
begin
i:=1;
Names:= Names + ' ';
While Names[i] <> ' ' do begin
dictName:= dictName + Names[i];
i:= i + 1;
end;
dictName:= 'c:\\Users\абвг\Desktop\' + dictName;
assign(dict, dictName);
i:=i + 1;
while Names[i] <> ' ' do begin
inpName := inpName + Names[i];
i:= i+ 1;
end;
inpName:= 'c:\\Users\абвг\Desktop\' + inpName;
assign(inp, inpName);
i:= i + 1;
while Names[i] <> ' ' do begin
outpName := outpName + Names[i];
i:= i + 1;
end;
outpName:= 'c:\\Users\абвг\Desktop\' + outpName;
assign(outp, outpName);
end;
procedure AddToTree(var T: tTree; K: String);
begin
if T = nil then begin
new(T);
T^.Key := K;
T^.Count := 0;
T^.Left := nil;
T^.Right := nil;
end
else if (K = T^.key) then
T^.count := T^.count + 1
else if (K < T^.Key) then
AddToTree(T^.Left, K)
else if (K > T^.Key) then
AddToTree(T^.Right, K);
end;
procedure PrintTree(t : tTree);
begin
if t <> nil then begin
PrintTree(t^.left);
writeln(t^.key, ' ', t^.count);
PrintTree(t^.right);
end;
end;
var
FileNames : string;
dict, inp, outp : text;
t : tTree;
wordcount : integer;
procedure WriteAllWordsInTree(dict : text; t : tTree);
var
wrd : string;
begin
reset(dict);
t := nil;
while not eof(dict) do begin
readln(dict, wrd);
if (wrd <> ' ') or (wrd <> '') then
AddToTree(t, wrd);
end;
end;
procedure ClearUncorrectSymbols(inp: text; var outp : text);
var
ch : char;
s : string;
begin
reset(inp);
rewrite(outp);
while not eof(inp) do begin
while not eoln(inp) do begin
read(inp, ch);
if ch in CorrectSymbols then
write(outp, Upcase(ch))
else
writeln(outp);
end;
readln(inp);
writeln(outp);
end;
close(outp);
end;
procedure SearchWordInTree(outp: text; var t : tTree; var wordcount :integer);
var
res : tPtr;
wrd : string;
begin
wordcount := 0;
reset(outp);
WriteAllWordsInTree(dict, t);
while not eof(outp) do begin
readln(outp, wrd);
if wrd <> '' then begin
wrd := UpperCase(wrd);
Search(t, wrd, res);
if res <> nil then
res^.count := res^.count +1;
end;
end;
close(outp);
end;
procedure PrintTreeInFile(var outp :text; t : tTree; wordcount : integer);
var
W: integer;
begin
if T <> nil then begin
W := abs(50 - length(T^.key));
PrintTreeInFile(outp, T^.left, wordcount);
writeln(outp, T^.Key , T^.count:w, ' ', (T^.count / wordcount)*100:3:2,'%');
PrintTreeInFile(outp, T^.right, wordcount);
end;
end;
begin
assign(dict, 'C:\\Users\абвг\desktop\dict.txt');
assign(inp, 'C:\\Users\абвг\desktop\dirt.txt');
assign(outp, 'C:\\Users\абвг\desktop\OUTtext.txt');
writeln('Statistics of files');
writeln('Enter files <dictionary> <input> <output>');
writeln('for example : dict.txt f.txt stat.txt');
{readln(FileNames);}
{AssignFiles(FileNames, dict, inp, outp);}
ClearUncorrectSymbols(inp, outp);
SearchWordInTree(outp, t, wordcount);
rewrite(outp);
PrintTreeInFile(outp, t, wordcount);
close(outp);
if t = nil then
writeln('VSEPROPALO');
end. |