ํฐ์คํ ๋ฆฌ ๋ทฐ
dev/algorithm
BOJ / 16165๋ฒ / ๊ฑธ๊ทธ๋ฃน ๋ง์คํฐ ์ค์์ด [Go][Python3]
crscnt 2021. 2. 28. 21:00๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/16165
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)
groupInfos := map[string]groupInfo{}
memberInfos := map[string]string{}
for i := 0; i < n; i++ {
var groupName string
fmt.Fscanln(reader, &groupName)
var memberCount int
fmt.Fscanln(reader, &memberCount)
info := groupInfo{groupName: groupName}
for j := 0; j < memberCount; j++ {
var memberName string
fmt.Fscanln(reader, &memberName)
info.members = append(info.members, memberName)
memberInfos[memberName] = groupName
}
groupInfos[groupName] = info
}
for i := 0; i < m; i++ {
var quiz string
fmt.Fscanln(reader, &quiz)
var quizType int
fmt.Fscanln(reader, &quizType)
if quizType == 0 {
sort.Strings(groupInfos[quiz].members)
for _, v := range groupInfos[quiz].members {
fmt.Fprintln(writer, v)
}
} else if quizType == 1 {
fmt.Fprintln(writer, memberInfos[quiz])
}
}
}
type groupInfo struct {
groupName string
members []string
}
๐จ Python3
# https://www.acmicpc.net/problem/16165
import sys
if __name__ == "__main__":
n, m = list(map(int, sys.stdin.readline().split()))
group_infos = {}
member_infos = {}
for i in range(n):
group_name = sys.stdin.readline().rstrip()
member_count = int(sys.stdin.readline())
members = []
for j in range(member_count):
member_name = sys.stdin.readline().rstrip()
members.append(member_name)
member_infos[member_name] = group_name
group_infos[group_name] = (group_name, members)
for i in range(m):
quiz = sys.stdin.readline().rstrip()
quiz_type = int(sys.stdin.readline())
if quiz_type == 0:
for j in sorted(group_infos[quiz][1]):
print(j)
elif quiz_type == 1:
print(member_infos[quiz])
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 13305๋ฒ / ์ฃผ์ ์ [Go][Python3] (0) | 2021.03.02 |
---|---|
BOJ / 4796๋ฒ / ์บ ํ [Go][Python3] (0) | 2021.03.01 |
BOJ / 11478๋ฒ / ์๋ก ๋ค๋ฅธ ๋ถ๋ถ ๋ฌธ์์ด์ ๊ฐ์ [Go][Python3] (0) | 2021.02.27 |
BOJ / 1789๋ฒ / ์๋ค์ ํฉ [Go][Python3] (0) | 2021.02.26 |
BOJ / 10994๋ฒ / ๋ณ ์ฐ๊ธฐ 19 [Go][Python3] (0) | 2021.02.25 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ธ๋ฃจํธํฌ์ค
- ์คํ
- BFS
- ์๊ณ ๋ฆฌ์ฆ
- ๋ฐฑ์ค
- ๋ชฝ๊ณ ๋๋น
- Algorithm
- dfs
- Macbook pro 2012 mid 13
- ํ๋ก์ด๋์์ฌ
- dp
- ๋ถํ ์ ๋ณต
- ์ด๋ถํ์
- java
- ์๋ฐ
- ๋งฅ๋ถ
- ์๊ฐ๊ต์ฒด
- ํด์๋งต
- ๋ฐ๋
- go
- BOJ
- AWS
- python3
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- Golang
- baekjoon
- ballet
- MongoDB
- ํ
- ๋งฅ๋ถํ๋ก
- Total
- Today
- Yesterday