SpamChecker
TCO14 Round 1B · 2014-03-26 · by tozangezan
TCO14 Round 1B · 2014-03-26 · by tozangezan · Simulation
Problem Statement
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 aString 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.
In the pseudocode, G and B are positive integers. You are given their values asint s good and bad.
Return "SPAM" (quotes for clarity) if the e-mail described by judgeLog is a spam, and "NOT SPAM" otherwise.
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.
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"
Submissions are judged against all 79 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class SpamChecker with a public method string spamCheck(string judgeLog, int good, int bad) · 79 test cases · 2 s / 256 MB per case