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 and
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
Keep in mind escape characters if you are using java. Tip of advice lol
using Python
I don't get where I am making a mistake, it seems to me I covered all possible cases. Any tip will be appreciated.
You can try the case
:)
oraaaaaaaaaaaaaaa
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 anif
statement - isif happy or sad in message
really checking what you think it is?what does IR mean as an error
Invalid return (i.e. it crashed).
https://dmoj.ca/about/codes/
Ok thanks
Can anyone tell me why my code gets a WA?
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.
Ok thanks!
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
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.
cin >> input
won't get the entire line, just until the first space. It's better to usegetline(cin, input);
Thanks!
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 :-(
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");
the comment was on march 22, 2019 and that was the point of it. he exchanged sad with unhappy. ;-;
welcome to the world of CCC
This comment is hidden due to too much negative feedback. Show it anyway.
read the question before asking
This will not happen.