Skip to content

Commit 761b36f

Browse files
committed
CF329A
1 parent 624e2db commit 761b36f

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

main/300-399/329A.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF329A(_r io.Reader, _w io.Writer) {
11+
in := bufio.NewReader(_r)
12+
out := bufio.NewWriter(_w)
13+
defer out.Flush()
14+
15+
var n, cr, cc int
16+
var s string
17+
Fscan(in, &n)
18+
r := make([]int, n)
19+
c := make([]int, n)
20+
for i := 0; i < n; i++ {
21+
Fscan(in, &s)
22+
for j, b := range s {
23+
if b == '.' {
24+
if r[j] == 0 {
25+
r[j] = i + 1
26+
cr++
27+
}
28+
if c[i] == 0 {
29+
c[i] = j + 1
30+
cc++
31+
}
32+
}
33+
}
34+
}
35+
if cr == n {
36+
for i, v := range r {
37+
Fprintln(out, v, i+1)
38+
}
39+
} else if cc == n {
40+
for i, v := range c {
41+
Fprintln(out, i+1, v)
42+
}
43+
} else {
44+
Fprint(out, -1)
45+
}
46+
}
47+
48+
//func main() { CF329A(os.Stdin, os.Stdout) }

main/300-399/329A_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/329/A
9+
// https://codeforces.com/problemset/status/329/problem/A
10+
func TestCF329A(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
3
15+
.E.
16+
E.E
17+
.E.
18+
outputCopy
19+
1 1
20+
2 2
21+
3 3
22+
inputCopy
23+
3
24+
EEE
25+
E..
26+
E.E
27+
outputCopy
28+
-1
29+
inputCopy
30+
5
31+
EE.EE
32+
E.EE.
33+
E...E
34+
.EE.E
35+
EE.EE
36+
outputCopy
37+
3 3
38+
1 3
39+
2 2
40+
4 4
41+
5 3`
42+
testutil.AssertEqualCase(t, rawText, 0, CF329A)
43+
}

0 commit comments

Comments
 (0)