Movements on the ground P79784


Statement
 

pdf   zip

html

Write a program that reads a sequence of characters, each one codifying a movement (‘n’ ‍for north, ‘s’ for south, ‘e’ for east, and ‘w’ for west), and that computes the final position of an object initially located at (0, 0). Suppose that the first component corresponds to the east-west direction, that going est means adding 1 to that component, and that going south means adding 1 to the second component.

Input

Input consists of a sequence of characters ‘n’, ‘s’, ‘e’, or ‘w’.

Output

Print the final position of an object initially located at (0, 0).

Public test cases
  • Input

    nnnn
    

    Output

    (0, -4)
    
  • Input

    ssewwwwn
    

    Output

    (-3, 1)
    
  • Input

    
            
                                

    Output

    (0, 0)
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Java Python
    User solutions
    C C++ Java Python Rust