ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

16165๋ฒˆ: ๊ฑธ๊ทธ๋ฃน ๋งˆ์Šคํ„ฐ ์ค€์„์ด

์ •์šฐ๋Š” ์†Œ๋ฌธ๋‚œ ๊ฑธ๊ทธ๋ฃน ๋•ํ›„์ด๋‹ค. ์ •์šฐ์˜ ์นœ๊ตฌ ์ค€์„์ด๋„ ๊ฑธ๊ทธ๋ฃน์„ ์ข‹์•„ํ•˜์ง€๋งŒ ์ด๋ฆ„์„ ์ž˜ ์™ธ์šฐ์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค. ์ •์šฐ๋Š” ์นœ๊ตฌ๋ฅผ ์œ„ํ•ด ๊ฑธ๊ทธ๋ฃน ๊ฐœ์ธ๊ณผ ํŒ€์˜ ์ด๋ฆ„์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ ์™ธ์šฐ๊ฒŒ ํ•˜๋Š”

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ 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
๋Œ“๊ธ€