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

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

 

2204๋ฒˆ: ๋„๋น„์˜ ๋‚œ๋…์ฆ ํ…Œ์ŠคํŠธ

๊ฟ์€ ๋„๋น„์—๊ฒŒ ์˜์–ด๋‹จ์–ด๋“ค์„ ์ œ์‹œํ•œ ํ›„ ์–ด๋–ค ๋‹จ์–ด๊ฐ€ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์ „์ˆœ์œผ๋กœ ๊ฐ€์žฅ ์•ž์„œ๋Š”์ง€ ๋งž์ถ”๋ฉด ์–‘๋ง์„ ์ฃผ์–ด ์ž์œ ๋ฅผ ์–ป๊ฒŒํ•ด์ค€๋‹ค๊ณ  ํ•˜์˜€๋‹ค. ํ•˜์ง€๋งŒ ์ธ์„ฑ์ด ์ข‹์ง€ ์•Š์€ ๊ฟ์€ ์‚ฌ์‹ค

www.acmicpc.net


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

๐ŸŽจ Go

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

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

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

	for {
		var n int
		fmt.Fscanln(reader, &n)
		if n == 0 {
			break
		}
		var words []string
		for i := 0; i < n; i++ {
			var word string
			fmt.Fscanln(reader, &word)
			words = append(words, word)
		}
		sort.Slice(words, func(i, j int) bool {
			return strings.ToLower(words[i]) < strings.ToLower(words[j])
		})
		fmt.Fprintln(writer, words[0])
	}
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    while True:
        n = int(sys.stdin.readline())
        if n == 0:
            break
        words = []
        for i in range(n):
            words.append(sys.stdin.readline().rstrip())
        print(sorted(words, key=lambda x: x.lower())[0])
728x90
๋Œ“๊ธ€