-
Notifications
You must be signed in to change notification settings - Fork 0
/
pregmatch.php
69 lines (37 loc) · 1.75 KB
/
pregmatch.php
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
<?php
/* --- QUESTION--
Munene is extremely disappointed to find out that no one in the office knows his first name. Even his close
mates call him only by his last name. Frustrated, he decides to make his fellow workmates know his first
name by forcing them to solve this question.
You are given a long string as input in each testcase, containing any ASCII character. Your task is to find
out the number of times SUVO and SUVOJIT appears in it.
Note: This problem CAN BE SOLVED IN Java, Python or PHP.
Input Format
The first line contains the number of testcases, T. Next, T lines follow each containing a long string S.
Output Format
For each long string S, display the no. of times SUVO and SUVOJIT appears in it.
Constraints
1 <= T <= 100
1 <= Length of each string <= 150
SAMPLE INPUT SAMPLE OUTPUT
SUVOJITSU SUVO = 0, SUVOJIT = 1
651SUVOMN SUVO = 1, SUVOJIT = 0
$$$$$SUVOSUVOJIT$$$$$ SUVO = 1, SUVOJIT = 1
*/
// --- ANSWER ---
$s = "651SUVOMN";
$suvo = "SUVO";
$suvojit = "SUVOJIT";
$s_temp = $s;
str_replace($suvojit, "", $s_temp);
$munene = new Munene();
class Munene{
public function find($string, $phrase){
$temp = $string;
str_replace($phrase, "", $temp);
$noOfTimesItAppears = (strlen($string) - strlen($temp))/strlen($phrase);
return $phrase." = ".$noOfTimesItAppears;
}
}
echo($munene->find($s_temp,$suvo).", ".$munene->find($s,$suvojit));
?>