CCC '15 J2 - Happy or Sad

View as PDF

Submit solution


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

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


  • -7
    andrue111  commented on Sept. 28, 2024, 8:31 p.m. edited

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


  • -11
    Eason_liu_python  commented on Sept. 13, 2024, 1:36 a.m. edited

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


  • -3
    aimalie98  commented on Oct. 25, 2023, 5:56 p.m. edited

    I am super stuck on this problem and I don't know how to fix it. I have just learned about and, if statements but have not encountered loops or length functions yet so I am with a very light tool belt to solve this problem. Is there a hint for a very very simple code to count the number of happy and sad faces?

    This was my best guess:

    line = str(input())
    
    if line .count(':-)') == 0 or line .count(':-(') == 0:
    
        print('none')
    
    elif line .count(':-)') == line .count(':-('):
    
        print('unsure')
    
    elif line .count(':-)') > line .count(':-('):
    
        print('happy')
    
    
    elif line .count(':-)') < line .count(':-('):
    
        print('sad')
    

    • -3
      JoeP  commented on Nov. 19, 2023, 12:26 p.m. edit 2

      aimalie98 I just tryed your code with and in stead of you "or" in the first if sentence and it is judged AC in all trials! So thank you for showing me how it can be written better that I have done it. JoeP


    • -4
      JoeP  commented on Nov. 19, 2023, 12:17 p.m. edit 2

      aimalie98! your code line that reads: "if line .count(':-)') == 0 or line .count(':-(') == 0:" should be: if line .count(':-)') == 0 and line .count(':-(') == 0: in stead for print('none') corresponds to the case when both sad and happy are zero and in your way of putting it when only one is zero so the program will return answer "none". That is the error I put my eye on but there are surely other that may have written this problem even better. My code that reads as follows:

      string = str(input())
      g = int(string .count(':-)'))
      s = int(string .count(':-('))
      
      if g > s:
          print('happy')
      elif s > g:
          print('sad')
      elif s == g:
          print('unsure')
      elif s == 0 and g == 0:
          print('none')
      

      returns one WA and the rest AC i.e. 13 of possible 15 score. And I do not know whats wrong with it? Can you come with the answer??!!!


      • 0
        Daquine  commented on Dec. 14, 2023, 9:57 p.m. edited

        Technically, the code is correct, it's the order in which each if statement is written out (although I changed it up just a bit).

        the order is:

        if happy < 1 and sad < 1: 
            print('none')
        elif sad == happy:
            print('unsure')
        elif happy > sad:
            print('happy')
        elif sad > happy:
            print('sad')
        

        I posted it in this order and I got all of them correct.

        This whole thread really helped me too, because I was lost with doing strings, and not just integers.


        • 0
          曲意  commented on April 3, 2024, 11:50 a.m. edit 2

          I think the right answer is this:

          n1 = a.count(":-)")
          n2 = a.count(":-(")
          
          if n1 + n2 != 0: