Skip to content

Commit 483656d

Browse files
committed
CF1167D 括号染色
1 parent 5aabca5 commit 483656d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

main/1100-1199/1167D.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1167D(_r io.Reader, _w io.Writer) {
11+
in := bufio.NewReader(_r)
12+
out := bufio.NewWriter(_w)
13+
defer out.Flush()
14+
15+
var n int
16+
var s string
17+
Fscan(in, &n, &s)
18+
for i, b := range s {
19+
if i&1 > 0 == (b == '(') {
20+
Fprint(out, 1)
21+
} else {
22+
Fprint(out, 0)
23+
}
24+
}
25+
}
26+
27+
//func main() { CF1167D(os.Stdin, os.Stdout) }

main/1100-1199/1167D_test.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+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/1167/D
9+
// https://codeforces.com/problemset/status/1167/problem/D
10+
func TestCF1167D(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
2
15+
()
16+
outputCopy
17+
11
18+
inputCopy
19+
4
20+
(())
21+
outputCopy
22+
0101
23+
inputCopy
24+
10
25+
((()())())
26+
outputCopy
27+
0110001111`
28+
testutil.AssertEqualCase(t, rawText, 0, CF1167D)
29+
}

0 commit comments

Comments
 (0)