Statistics

Problem Statement for "SpamChecker"

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)
(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

  1. "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.

  2. "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.

  3. "xooooooooooooooooooooooooooo"

    1000

    1

    Returns: "SPAM"

  4. "oxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

    1000

    1

    Returns: "NOT SPAM"

  5. "ooxoxoxooxoxxoxoxooxoxoxoxxoxx"

    15

    17

    Returns: "SPAM"

  6. "oooxoxoxoxoxoxooxooxoxooxo"

    16

    18

    Returns: "NOT SPAM"

  7. "o"

    1

    1

    Returns: "NOT SPAM"

  8. "x"

    1

    1

    Returns: "SPAM"

  9. "ox"

    1

    1

    Returns: "NOT SPAM"

  10. "xo"

    1

    1

    Returns: "SPAM"

  11. "oo"

    1

    1

    Returns: "NOT SPAM"

  12. "xx"

    1

    1

    Returns: "SPAM"

  13. "oxoxxxxxoooooxoxxoxooxxxooxxoooxxo"

    945

    921

    Returns: "SPAM"

  14. "xxooxxxoooo"

    191

    492

    Returns: "SPAM"

  15. "xooxoxoxxxoxxxxoxooooooooxxoxxoooxoxxooxoxxoo"

    964

    657

    Returns: "SPAM"

  16. "oxxxxoxxxoox"

    565

    848

    Returns: "SPAM"

  17. "oxoxooooooxxoxxoooxxoxxooxoxxooxxoxoxooxooxxooxx"

    303

    788

    Returns: "SPAM"

  18. "oxxxxoxoxox"

    220

    387

    Returns: "SPAM"

  19. "o"

    683

    56

    Returns: "NOT SPAM"

  20. "oxxxoxxooxoxoxoxoxooxooox"

    874

    949

    Returns: "SPAM"

  21. "xxox"

    144

    645

    Returns: "SPAM"

  22. "oooooxoooooxoxxoooooooxoxoxxxooxxxoxxxxoo"

    80

    955

    Returns: "SPAM"

  23. "oox"

    433

    837

    Returns: "NOT SPAM"

  24. "oooxoxxoxooxxo"

    155

    529

    Returns: "SPAM"

  25. "oxxxxxooxooooxoxxooooxxxoxxoxoo"

    408

    750

    Returns: "SPAM"

  26. "xoooxxxooooxxoxxxooooxxxooxoxoxxooooo"

    842

    459

    Returns: "SPAM"

  27. "oooooxxoooxxoxooxxxooxxoxxooooxoxxooxoxoxxoxxoxoo"

    448

    25

    Returns: "NOT SPAM"

  28. "oxo"

    589

    793

    Returns: "SPAM"

  29. "oxxxo"

    507

    729

    Returns: "SPAM"

  30. "xxxxxxooooxoxxxxxxooooxxxoooxoooooxooxxxoo"

    642

    581

    Returns: "SPAM"

  31. "xoxxxxxxooooxoxxx"

    672

    605

    Returns: "SPAM"

  32. "oxooooxooxxxxxxxxxxooxo"

    649

    894

    Returns: "SPAM"

  33. "ooxxxxox"

    453

    610

    Returns: "SPAM"

  34. "xxxooxxxxooxxxooxxoxxoo"

    225

    778

    Returns: "SPAM"

  35. "xooxooooxoxxxooxxxxoxxoooxx"

    343

    762

    Returns: "SPAM"

  36. "ooxoxxooxooxxxxooxoxxxxxxxxxoxxoxxooxxxoooxoxoxx"

    494

    786

    Returns: "SPAM"

  37. "ooxoooxoxxxoxooooo"

    716

    577

    Returns: "NOT SPAM"

  38. "xoxxoxxxxxoxxoxoooooxxxooxxoxxxoooxxooooooooxooooo"

    596

    354

    Returns: "SPAM"

  39. "oxxxxoxoxxooxoooxxoxxoxoooxxoxxoxxxoxxoxxoxxxxox"

    26

    644

    Returns: "SPAM"

  40. "ooooxo"

    357

    740

    Returns: "NOT SPAM"

  41. "xoooxoxoxxxxxoxooxxoxooo"

    912

    58

    Returns: "SPAM"

  42. "oxoxooxxxxoxxooxxoo"

    438

    614

    Returns: "SPAM"

  43. "xo"

    3

    1

    Returns: "SPAM"

  44. "x"

    1

    5

    Returns: "SPAM"

  45. "xoo"

    10

    10

    Returns: "SPAM"

  46. "oxxoooo"

    4

    7

    Returns: "SPAM"

  47. "xoooo"

    2

    1

    Returns: "SPAM"

  48. "xoooo"

    10

    3

    Returns: "SPAM"

  49. "ox"

    20

    30

    Returns: "SPAM"

  50. "xxoo"

    2

    2

    Returns: "SPAM"

  51. "xxxoooo"

    2

    2

    Returns: "SPAM"

  52. "xo"

    100

    10

    Returns: "SPAM"

  53. "xooooo"

    100

    1

    Returns: "SPAM"

  54. "xoooo"

    1000

    1

    Returns: "SPAM"

  55. "xoooooooooo"

    1

    1

    Returns: "SPAM"

  56. "ox"

    5

    5

    Returns: "NOT SPAM"

  57. "ox"

    2

    5

    Returns: "SPAM"

  58. "ox"

    2

    3

    Returns: "SPAM"

  59. "ox"

    2

    2

    Returns: "NOT SPAM"

  60. "xoooo"

    1

    1

    Returns: "SPAM"

  61. "oxxxooooo"

    1

    1

    Returns: "SPAM"

  62. "xo"

    2

    1

    Returns: "SPAM"

  63. "xo"

    10

    9

    Returns: "SPAM"

  64. "ooooooooooooooooooooooooooooooooooooooooooooooooox"

    1

    1000

    Returns: "SPAM"

  65. "xxoooo"

    5

    1

    Returns: "SPAM"

  66. "xoo"

    30

    5

    Returns: "SPAM"

  67. "oooxxx"

    1

    1

    Returns: "NOT SPAM"

  68. "x"

    2

    3

    Returns: "SPAM"

  69. "ox"

    2

    1

    Returns: "NOT SPAM"

  70. "ox"

    1

    2

    Returns: "SPAM"

  71. "ooxxx"

    1

    1

    Returns: "SPAM"

  72. "xo"

    5

    1

    Returns: "SPAM"

  73. "x"

    100

    100

    Returns: "SPAM"

  74. "x"

    5

    10

    Returns: "SPAM"

  75. "xoo"

    1

    1

    Returns: "SPAM"

  76. "xxx"

    2

    2

    Returns: "SPAM"

  77. "ox"

    3

    3

    Returns: "NOT SPAM"

  78. "ox"

    5

    10

    Returns: "SPAM"

  79. "x"

    5

    7

    Returns: "SPAM"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: