CCC '15 J2 - Happy or Sad

View as PDF

Submit solution


Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type
Canadian Computing Competition: 2015 Stage 1, Junior #2

We often include emoticons in our text messages to indicate how we are feeling. The three consecutive characters :-) indicate a happy face and the three consecutive characters :-( indicate a sad face. Write a program to determine the overall mood of a message.

Input Specification

There will be one line of input that contains between 1 and 255 characters.

Output Specification

The output is determined by the following rules:

  • If the input line does not contain any happy or sad emoticons, output none.
  • Otherwise, if the input line contains an equal number of happy and sad emoticons, output unsure.
  • Otherwise, if the input line contains more happy than sad emoticons, output happy.
  • Otherwise, if the input line contains more sad than happy emoticons, output sad.

Sample Input 1

How are you :-) doing :-( today :-)?

Output for Sample Input 1

happy

Sample Input 2

:)

Output for Sample Input 2

none

Sample Input 3

This :-(is str :-(:-a(nge te:-)xt.

Output for Sample Input 3

sad

Comments


  • -2
    jonathansun  commented on Feb. 7, 2022, 3:33 p.m.

    Keep in mind escape characters if you are using java. Tip of advice lol


    • -1
      Jamkis9921  commented on Feb. 7, 2022, 4:53 p.m.

      using Python


  • 0
    neo_coder  commented on Nov. 19, 2021, 2:22 a.m.

    I don't get where I am making a mistake, it seems to me I covered all possible cases. Any tip will be appreciated.


    • 1
      uselessleaf  commented on Nov. 19, 2021, 10:24 a.m.

      You can try the case :) or aaaaaaaaaaaaaaa

      Hopefully by trying these cases, you'll see that something is wrong with your if statement on line 5 🤔

      In case you're still struggling, remember to check on either side of an or in an if statement - is if happy or sad in message really checking what you think it is?


  • 0
    0Power10  commented on July 12, 2021, 9:28 p.m.

    what does IR mean as an error


  • 4
    mahes0640  commented on Feb. 7, 2021, 1:32 p.m.

    Can anyone tell me why my code gets a WA?


    • 4
      BamTargetShock_Java  commented on Feb. 7, 2021, 2:48 p.m.

      Python's "in" operator only checks if a substring appears in a string, and not how times it appears in the string. So for example, :-):-):-) is one word that contains three happy faces, but your code would read it as one happy face.


      • 4
        mahes0640  commented on Feb. 12, 2021, 2:20 p.m.

        Ok thanks!


  • 10
    cyopotatoe  commented on June 12, 2020, 5:10 p.m. edited

    Well determine the tone of this! :-I

    This is not me being stupid and not reading the instructions, it's a bad attempt at humor


  • 1
    Frontear  commented on Nov. 22, 2019, 9:28 a.m.

    I'm a bit unsure as to why my solution isn't working as intended. I've tried some of my personal test cases, and they work fine, but I can't seem to pass most of the test cases.


    • 4
      Dingledooper  commented on Nov. 22, 2019, 7:10 p.m. edit 2

      cin >> input won't get the entire line, just until the first space. It's better to use getline(cin, input);


  • 14
    Zanger  commented on March 22, 2019, 1:45 a.m.

    I just spend 20 minutes trying to find any small error in my code despite this being a low difficulty question just to find that I wrote an output as "unhappy" instead of "sad"... fml :-(


    • -4
      GamerWolf67  commented on April 13, 2021, 5:53 p.m. edited

      When you make it output the specified word, be careful not to do:

      System.out.println("unhappy"); if it's Java. Instead, do: System.out.println("sad");


      • 1
        henrybaolol9  commented on April 13, 2021, 7:12 p.m. edited

        the comment was on march 22, 2019 and that was the point of it. he exchanged sad with unhappy. ;-;


    • 6
      slowmomoe  commented on April 13, 2019, 3:53 p.m.

      welcome to the world of CCC


  • -31
    AliSatec  commented on Jan. 11, 2017, 3:09 p.m. edited

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 0
      Jaffy  commented on March 12, 2022, 7:48 p.m.

      read the question before asking


    • 5
      Kirito  commented on Jan. 11, 2017, 3:17 p.m.

      There will be one line of input that contains between 1 and 255 characters.

      This will not happen.