ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1764
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, m int
fmt.Fscanln(reader, &n, &m)
var dbj = map[string]int{}
for i := 0; i < n; i++ {
var input string
fmt.Fscanln(reader, &input)
dbj[input]++
}
for i := 0; i < m; i++ {
var input string
fmt.Fscanln(reader, &input)
dbj[input]++
}
keys := []string{}
for key, val := range dbj {
if val == 2 {
keys = append(keys, key)
}
}
sort.Strings(keys)
fmt.Fprintln(writer, len(keys))
for _, key := range keys {
fmt.Fprintln(writer, key)
}
}
๐จ Python3
# https://www.acmicpc.net/problem/1764
import sys
if __name__ == "__main__":
n, m = list(map(int, sys.stdin.readline().split()))
dbj = {}
for i in range(n):
input = sys.stdin.readline().rstrip()
if dbj.get(input):
dbj[input] += 1
else:
dbj[input] = 1
for i in range(m):
input = sys.stdin.readline().rstrip()
if dbj.get(input):
dbj[input] += 1
else:
dbj[input] = 1
dbj_result = []
for (key, value) in dbj.items():
if value == 2:
dbj_result.append(key)
dbj_result.sort()
print(len(dbj_result))
for i in dbj_result:
print(i)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1927๋ฒ / ์ต์ ํ [Go][Python3] (0) | 2020.11.29 |
---|---|
BOJ / 11279๋ฒ / ์ต๋ ํ [Go][Python3] (0) | 2020.11.28 |
BOJ / 10815๋ฒ / ์ซ์ ์นด๋ [Go][Python3] (0) | 2020.11.26 |
BOJ / 2110๋ฒ / ๊ณต์ ๊ธฐ ์ค์น [Go][Python3] (0) | 2020.11.25 |
BOJ / 20207๋ฒ / ๋ฌ๋ ฅ [Go] (0) | 2020.11.24 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ชฝ๊ณ ๋๋น
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์คํ
- Macbook pro 2012 mid 13
- ํ
- ๋ฐฑ์ค
- MongoDB
- dfs
- dp
- baekjoon
- ์๋ฐ
- ์๊ณ ๋ฆฌ์ฆ
- ๋งฅ๋ถํ๋ก
- go
- ํด์๋งต
- BFS
- AWS
- BOJ
- ํ๋ก์ด๋์์ฌ
- ๋ธ๋ฃจํธํฌ์ค
- ์๊ฐ๊ต์ฒด
- java
- ์ด๋ถํ์
- ๋ฐ๋
- ๋งฅ๋ถ
- ballet
- ๋ถํ ์ ๋ณต
- python3
- Algorithm
- Golang
- Total
- Today
- Yesterday