Happiness and Sadness (2) X70475


Statement
 

pdf   zip

html

We define the happiness level of a text as the number of occurrences of subwords of the following two types:

  • Those formed by a character ’:’, followed by one or more characters ’-’, followed by a character ’)’. For example, ":-)", ":--)" and ":---)" would be of this type.
  • Those formed by a character ’(’, followed by one or more characters ’-’, followed by a character ’:’. For example, "(-:", "(--:" and "(---:" whould be of this type.

We define the sadness level of a text as the number of occurrences of subwords of the following two types:

  • Those formed by a character ’:’, followed by one or more characters ’-’, followed by a character ’(’. For example, ":-(", ":--(" and ":---(" would be of this type.
  • Those formed by a character ’)’, followed by one or more characters ’-’, followed by a character ’:’. For example, ")-:", ")--:" i ")---:" whould be of this type.

Implement a program such that, given a sequence of characters from {’-’, ’:’, ’(’, ’)’}, prints its level of happiness and sadness.

Input

The input contains only one line with a sequence of characters from {’-’, ’:’, ’(’, ’)’}.

Output

The output has two numbers separated by a white space, the happiness and sadness levels of the input text.

Observation

Do not use strings nor any other massive data storage method. Read and treat the input character by character.

Public test cases
  • Input

    )-:--(--::((:-:)):::))-(((--)(:))::-(((((-:((--(-((:-)))-:--(-:(-:))(---(-)-(-):)-:::))-::((-(:())--

    Output

    5 7
    
  • Input

    :-)-:-(-:-)-::-((-:--)-::::--(-:

    Output

    6 6
    
  • Input

    ::---)-::--(((--:-)----::::-((((------::--)-::::--(-:::

    Output

    6 6
    
  • Information
    Author
    PRO1
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++