forked from ricardojpinheiro/nanomsx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfudeba.pas
More file actions
42 lines (39 loc) · 1.17 KB
/
fudeba.pas
File metadata and controls
42 lines (39 loc) · 1.17 KB
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
program teste;
type
linestring = string[255];
var
S: linestring;
teste: longint;
(* Finds the n-th occurence of a char which is into a string. *)
function NNPos(SearchPhrase, Phrase: linestring; Ntuple: byte): byte;
var
HowManyPos, ResultPos, counter, LengthPhrase, LengthSearchPhrase: byte;
temp: linestring;
begin
LengthPhrase := length (Phrase);
LengthSearchPhrase := length (SearchPhrase);
counter := 1;
ResultPos := 0;
HowManyPos := 0;
while (counter <= LengthPhrase) and (HowManyPos < Ntuple) do
begin
temp := copy(Phrase, counter, LengthSearchPhrase);
if SearchPhrase = temp then
begin
ResultPos := counter;
HowManyPos := HowManyPos + 1;
end;
counter := counter + 1;
end;
NNPos := ResultPos;
end;
begin
S := 'abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz';
writeln(S, ' ', length(S));
writeln(NNPos('a', S, 1));
writeln(NNPos('o', S, 1));
writeln(NNPos('z', S, 1));
writeln(NNPos('o', S, 2));
writeln(NNPos('t', S, 1));
writeln(NNPos('Ricardo', S, 1));
end.