forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpamChecker.txt
99 lines (64 loc) · 2.38 KB
/
SpamChecker.txt
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
PROBLEM STATEMENT
Wolf Sothe was troubled with e-mail spam every day, so he decided to make his own spam filter.
Sothe's approach starts by looking at each line of the e-mail separately and classifying it either as good or bad.
The more bad lines an e-mail contains, the more likely it is a spam.
Sothe already implemented the above part, and you are given its output as a string judgeLog.
The characters of judgeLog correspond to the lines of an e-mail, in order.
The character 'o' represents a good line and the character 'x' represents a bad line.
For example, judgeLog="oxooo" corresponds to an e-mail with 5 lines.
The second line of this e-mail is bad and the other four lines are good.
Sothe now came up with an algorithm to decide whether an e-mail is spam. Pseudocode of the algorithm is shown below.
At the beginning, set the score of the e-mail to 0.
For each line of the e-mail, in order:
If the line is good, increase the score by G.
If the line is bad, decrease the score by B.
If the score is now negative (i.e., smaller than 0):
Classify the e-mail as "SPAM" and terminate.
If the score was never negative:
Classify the e-mail as "NOT SPAM" and terminate.
In the pseudocode, G and B are positive integers. You are given their values as ints good and bad.
Return "SPAM" (quotes for clarity) if the e-mail described by judgeLog is a spam, and "NOT SPAM" otherwise.
DEFINITION
Class:SpamChecker
Method:spamCheck
Parameters:string, int, int
Returns:string
Method signature:string spamCheck(string judgeLog, int good, int bad)
CONSTRAINTS
-judgeLog will contain between 1 and 50 characters, inclusive.
-Each character in judgeLog will be 'o' or 'x'.
-good will be between 1 and 1000, inclusive.
-bad will be between 1 and 1000, inclusive.
EXAMPLES
0)
"ooooxxxo"
2
3
Returns: "SPAM"
After the 7th line of this e-mail the score is 2+2+2+2-3-3-3 = -1. Hence, at that moment the e-mail gets classified as spam.
1)
"ooooxxxo"
3
4
Returns: "NOT SPAM"
In this case, the score of the e-mail will never be negative, so it gets classified as not spam. Note that after 7 lines of this e-mail the score is 0, but that does not make it a spam.
2)
"xooooooooooooooooooooooooooo"
1000
1
Returns: "SPAM"
3)
"oxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
1000
1
Returns: "NOT SPAM"
4)
"ooxoxoxooxoxxoxoxooxoxoxoxxoxx"
15
17
Returns: "SPAM"
5)
"oooxoxoxoxoxoxooxooxoxooxo"
16
18
Returns: "NOT SPAM"