TSS Contest P2 - Magnets

View as PDF

Submit solution

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

Author:
Problem type

A line of magnets can be represented as a string of -s, +s and 0s representing negative, positive and neutral charges respectively. A single magnet will always be composed of either a - or + at either end (these magnets can have both ends with the same charge) and at least one 0 in the middle. For example, -00+, -00000000- and +0- are all valid magnets. Consider the following scenario: You have two magnets with the ends touching. If these ends were opposite charges (-+) then these two magnets would become stuck together. Given a line of magnets, end to end, in the format described above, output the number of magnets stuck to at least one other magnet.

Input Specifications

A single string S with no spaces only containing the characters -,+ and 0. The length of S will be \le 10^3 characters.

Output Specifications

A single integer representing the number of magnets stuck together.

Sample Input

-00+-0++0+-00--0+

Sample Output

4

Comments

There are no comments at the moment.