Skip to content

Commit df2c740

Browse files
committed
CF4C
1 parent 4ffedcb commit df2c740

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

main/1-99/4C.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 CF4C(_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+
cnt := map[string]int{}
18+
for Fscan(in, &n); n > 0; n-- {
19+
Fscan(in, &s)
20+
if cnt[s] > 0 {
21+
Fprintf(out, "%s%d\n", s, cnt[s])
22+
} else {
23+
Fprintln(out, "OK")
24+
}
25+
cnt[s]++
26+
}
27+
}
28+
29+
//func main() { CF4C(os.Stdin, os.Stdout) }

main/1-99/4C_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/4/C
9+
// https://codeforces.com/problemset/status/4/problem/C
10+
func TestCF4C(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
4
15+
abacaba
16+
acaba
17+
abacaba
18+
acab
19+
outputCopy
20+
OK
21+
OK
22+
abacaba1
23+
OK
24+
inputCopy
25+
6
26+
first
27+
first
28+
second
29+
second
30+
third
31+
third
32+
outputCopy
33+
OK
34+
first1
35+
OK
36+
second1
37+
OK
38+
third1`
39+
testutil.AssertEqualCase(t, rawText, 0, CF4C)
40+
}

0 commit comments

Comments
 (0)