File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
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) }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments