Problem Statement
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
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
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)
- (be sure your method is public)
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
"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.
"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.
"xooooooooooooooooooooooooooo"
1000
1
Returns: "SPAM"
"oxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
1000
1
Returns: "NOT SPAM"
"ooxoxoxooxoxxoxoxooxoxoxoxxoxx"
15
17
Returns: "SPAM"
"oooxoxoxoxoxoxooxooxoxooxo"
16
18
Returns: "NOT SPAM"
"o"
1
1
Returns: "NOT SPAM"
"x"
1
1
Returns: "SPAM"
"ox"
1
1
Returns: "NOT SPAM"
"xo"
1
1
Returns: "SPAM"
"oo"
1
1
Returns: "NOT SPAM"
"xx"
1
1
Returns: "SPAM"
"oxoxxxxxoooooxoxxoxooxxxooxxoooxxo"
945
921
Returns: "SPAM"
"xxooxxxoooo"
191
492
Returns: "SPAM"
"xooxoxoxxxoxxxxoxooooooooxxoxxoooxoxxooxoxxoo"
964
657
Returns: "SPAM"
"oxxxxoxxxoox"
565
848
Returns: "SPAM"
"oxoxooooooxxoxxoooxxoxxooxoxxooxxoxoxooxooxxooxx"
303
788
Returns: "SPAM"
"oxxxxoxoxox"
220
387
Returns: "SPAM"
"o"
683
56
Returns: "NOT SPAM"
"oxxxoxxooxoxoxoxoxooxooox"
874
949
Returns: "SPAM"
"xxox"
144
645
Returns: "SPAM"
"oooooxoooooxoxxoooooooxoxoxxxooxxxoxxxxoo"
80
955
Returns: "SPAM"
"oox"
433
837
Returns: "NOT SPAM"
"oooxoxxoxooxxo"
155
529
Returns: "SPAM"
"oxxxxxooxooooxoxxooooxxxoxxoxoo"
408
750
Returns: "SPAM"
"xoooxxxooooxxoxxxooooxxxooxoxoxxooooo"
842
459
Returns: "SPAM"
"oooooxxoooxxoxooxxxooxxoxxooooxoxxooxoxoxxoxxoxoo"
448
25
Returns: "NOT SPAM"
"oxo"
589
793
Returns: "SPAM"
"oxxxo"
507
729
Returns: "SPAM"
"xxxxxxooooxoxxxxxxooooxxxoooxoooooxooxxxoo"
642
581
Returns: "SPAM"
"xoxxxxxxooooxoxxx"
672
605
Returns: "SPAM"
"oxooooxooxxxxxxxxxxooxo"
649
894
Returns: "SPAM"
"ooxxxxox"
453
610
Returns: "SPAM"
"xxxooxxxxooxxxooxxoxxoo"
225
778
Returns: "SPAM"
"xooxooooxoxxxooxxxxoxxoooxx"
343
762
Returns: "SPAM"
"ooxoxxooxooxxxxooxoxxxxxxxxxoxxoxxooxxxoooxoxoxx"
494
786
Returns: "SPAM"
"ooxoooxoxxxoxooooo"
716
577
Returns: "NOT SPAM"
"xoxxoxxxxxoxxoxoooooxxxooxxoxxxoooxxooooooooxooooo"
596
354
Returns: "SPAM"
"oxxxxoxoxxooxoooxxoxxoxoooxxoxxoxxxoxxoxxoxxxxox"
26
644
Returns: "SPAM"
"ooooxo"
357
740
Returns: "NOT SPAM"
"xoooxoxoxxxxxoxooxxoxooo"
912
58
Returns: "SPAM"
"oxoxooxxxxoxxooxxoo"
438
614
Returns: "SPAM"
"xo"
3
1
Returns: "SPAM"
"x"
1
5
Returns: "SPAM"
"xoo"
10
10
Returns: "SPAM"
"oxxoooo"
4
7
Returns: "SPAM"
"xoooo"
2
1
Returns: "SPAM"
"xoooo"
10
3
Returns: "SPAM"
"ox"
20
30
Returns: "SPAM"
"xxoo"
2
2
Returns: "SPAM"
"xxxoooo"
2
2
Returns: "SPAM"
"xo"
100
10
Returns: "SPAM"
"xooooo"
100
1
Returns: "SPAM"
"xoooo"
1000
1
Returns: "SPAM"
"xoooooooooo"
1
1
Returns: "SPAM"
"ox"
5
5
Returns: "NOT SPAM"
"ox"
2
5
Returns: "SPAM"
"ox"
2
3
Returns: "SPAM"
"ox"
2
2
Returns: "NOT SPAM"
"xoooo"
1
1
Returns: "SPAM"
"oxxxooooo"
1
1
Returns: "SPAM"
"xo"
2
1
Returns: "SPAM"
"xo"
10
9
Returns: "SPAM"
"ooooooooooooooooooooooooooooooooooooooooooooooooox"
1
1000
Returns: "SPAM"
"xxoooo"
5
1
Returns: "SPAM"
"xoo"
30
5
Returns: "SPAM"
"oooxxx"
1
1
Returns: "NOT SPAM"
"x"
2
3
Returns: "SPAM"
"ox"
2
1
Returns: "NOT SPAM"
"ox"
1
2
Returns: "SPAM"
"ooxxx"
1
1
Returns: "SPAM"
"xo"
5
1
Returns: "SPAM"
"x"
100
100
Returns: "SPAM"
"x"
5
10
Returns: "SPAM"
"xoo"
1
1
Returns: "SPAM"
"xxx"
2
2
Returns: "SPAM"
"ox"
3
3
Returns: "NOT SPAM"
"ox"
5
10
Returns: "SPAM"
"x"
5
7
Returns: "SPAM"