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

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

 

20291๋ฒˆ: ํŒŒ์ผ ์ •๋ฆฌ

์นœ๊ตฌ๋กœ๋ถ€ํ„ฐ ๋…ธํŠธ๋ถ์„ ์ค‘๊ณ ๋กœ ์‚ฐ ์Šค๋ธŒ๋Ÿฌ์Šค๋Š” ๋…ธํŠธ๋ถ์„ ์ผœ์ž๋งˆ์ž ๊ฒฝ์•…ํ•  ์ˆ˜๋ฐ–์— ์—†์—ˆ๋‹ค. ๋ฐ”ํƒ•ํ™”๋ฉด์— ์˜จ๊ฐ– ํŒŒ์ผ๋“ค์ด ์ •๋ฆฌ๋„ ์•ˆ ๋œ ์ฑ„ ๊ฐ€๋“ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ™”๋ฉด์˜ ๊ตฌ์„์—์„œ ์นœ๊ตฌ์˜ ๋ฉ”์‹œ์ง€๋ฅผ

www.acmicpc.net


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

๐ŸŽจ Go

// https://www.acmicpc.net/problem/20291
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanln(reader, &n)

	extMap := map[string]int{}
	for i := 0; i < n; i++ {
		var filepath string
		fmt.Fscanln(reader, &filepath)
		ext := strings.Split(filepath, ".")[1]
		extMap[ext]++
	}

	sortedKeys := []string{}
	for key := range extMap {
		sortedKeys = append(sortedKeys, key)
	}
	sort.Strings(sortedKeys)

	for _, key := range sortedKeys {
		fmt.Fprintf(writer, "%s %d\n", key, extMap[key])
	}
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/20291
import sys

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    ext_dict = {}
    for i in range(n):
        _, ext = sys.stdin.readline().rstrip().split(".")
        if ext_dict.get(ext):
            ext_dict[ext] += 1
        else:
            ext_dict[ext] = 1
    for key in sorted(ext_dict.keys()):
        print('{} {}'.format(key, ext_dict[key]))
728x90
๋Œ“๊ธ€