mirror of https://github.com/01-edu/public.git
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.
35 lines
1.1 KiB
35 lines
1.1 KiB
5 years ago
|
## balancedstring
|
||
|
|
||
|
### Instructions
|
||
|
|
||
|
Balanced string is a string that has equal quantity of 'C' and 'D' characters.
|
||
|
|
||
5 years ago
|
Write a program that takes a string and outputs maximum amount of balanced strings without ignoring any letters.
|
||
|
Display output with `\n` at the end of line.
|
||
5 years ago
|
|
||
5 years ago
|
If the number of arguments is not 1, display nothing.
|
||
5 years ago
|
|
||
5 years ago
|
It will only be tested strings containing the characters 'C' and 'D'.
|
||
5 years ago
|
|
||
|
### Usage
|
||
|
|
||
|
```console
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/balancedstring$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/balancedstring$ ./balancedstring "CDCCDDCDCD"
|
||
5 years ago
|
4
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/balancedstring$ ./balancedstring "CDDDDCCCDC"
|
||
5 years ago
|
3
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/balancedstring$ ./balancedstring "DDDDCCCC"
|
||
5 years ago
|
1
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/balancedstring$ ./balancedstring "CDCCCDDCDD"
|
||
5 years ago
|
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'
|