Happiness Score
InterviewTime limit1sMemory limit1024 MB
Given one message, count letters that appear in HAPPY and SAD, then print the happiness index as a percentage rounded to two decimals.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Jim is a boy who has been feeling down since the COVID-19 pandemic, and he feels like he carries the weight of the whole world. Jim wants to measure how happy his friends are. One method he thinks of is to analyze the text messages his friends send and judge whether they are happy. If a letter in a message appears in the word HAPPY, that letter is a happy letter. If it appears in the word SAD, it is a sad letter. The letter A appears in both words, so it counts as both happy and sad. The letter B appears in neither word, so it is neither happy nor sad.
The happiness index of a message is calculated from a happy score and a sad score. Each happy letter increases the happy score by one, and each sad letter increases the sad score by one. The happiness index is calculated as follows.
Letters that are neither happy nor sad are not counted in either or . If , the happiness index is assumed to be .
For example, suppose a friend sends this message.
SAD MOVIES ALWAYS MAKE ME CRY
The letter A appears 4 times (once in SAD, twice in ALWAYS, once in MAKE) and Y appears 2 times (once in ALWAYS, once in CRY), so the happy score is 6. The letter S appears 3 times (in SAD, MOVIES, and ALWAYS), A appears 4 times, and D appears once in SAD, so the sad score is 8. Since and , the index is , or 42.86%. Because the index is below 50%, the friend is sad.
Input
The input is given through standard input. It consists of one line containing a text message. The message is made only of English alphabet words in uppercase, and the words are separated by spaces. The maximum length of a word is 20, and the maximum number of words is 80.
Output
Print the happiness index as a percentage, without the % sign. Round it to two decimal places. If and are both 0, the happiness index is 0.5, so print 50.00. Note this case.