A line of magnets can be represented as a string of -
s, +
s and 0
s 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 with no spaces only containing the characters -
,+
and 0
. The length of will be characters.
Output Specifications
A single integer representing the number of magnets stuck together.
Sample Input
-00+-0++0+-00--0+
Sample Output
4
Comments