Skip to content

Commit 6010017

Browse files
committed
CF1108D
1 parent c7a6ec4 commit 6010017

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

main/1100-1199/1108D.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1108D(in io.Reader, out io.Writer) {
11+
t := []byte("RGB")
12+
var n, ans int
13+
var s []byte
14+
Fscan(bufio.NewReader(in), &n, &s)
15+
for i := 1; i < n; i++ {
16+
if s[i-1] == s[i] {
17+
ans++
18+
for _, c := range t {
19+
if c != s[i-1] && (i == n-1 || c != s[i+1]) {
20+
s[i] = c
21+
break
22+
}
23+
}
24+
}
25+
}
26+
Fprintf(out, "%d\n%s", ans, s)
27+
}
28+
29+
//func main() { CF1108D(os.Stdin, os.Stdout) }

main/1100-1199/1108D_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/1108/D
9+
// https://codeforces.com/problemset/status/1108/problem/D
10+
func TestCF1108D(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
9
15+
RBGRRBRGG
16+
outputCopy
17+
2
18+
RBGRGBRGR
19+
inputCopy
20+
8
21+
BBBGBRRR
22+
outputCopy
23+
2
24+
BRBGBRGR
25+
inputCopy
26+
13
27+
BBRRRRGGGGGRR
28+
outputCopy
29+
6
30+
BGRBRBGBGBGRG`
31+
testutil.AssertEqualCase(t, rawText, 0, CF1108D)
32+
}

0 commit comments

Comments
 (0)