You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

765 B

balancedstring

Instructions

Balanced string is a string that has equal quantity of 'C' and 'D' characters.

Write a program that takes a string and outputs maximum amount of balanced strings with \n at the end of line.

If the number of arguments is not 1, display \n.S

Usage

$> go build
$> ./main "CDCCDDCDCD"
4
$> ./main "CDDDDCCCDC"
3
$> ./main "DDDDCCCC"
1
$> ./main "CDCCCDDCDD"
2

In first example "CDCCDDCDCD" can be split into "CD", "CCDD", "CD", "CD", each substring contains same number of 'C' and 'D'.

Second, "CDDDDCCCDC" can be split into: "CD", "DDDCCC", "DC".

"DDDDCCCC" can be split into "DDDDCCCC".

"CDCCCDDCDD" can be split into: "CD", "CCCDDCDD", since each substring contains an equal number of 'C' and 'D'