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

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

 

5635๋ฒˆ: ์ƒ์ผ

์–ด๋–ค ๋ฐ˜์— ์žˆ๋Š” ํ•™์ƒ๋“ค์˜ ์ƒ์ผ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋‚˜์ด๊ฐ€ ์ ์€ ์‚ฌ๋žŒ๊ณผ ๊ฐ€์žฅ ๋งŽ์€ ์‚ฌ๋žŒ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net


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

๐ŸŽจ Go

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

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

type studentFormat struct {
	name  string
	day   int
	month int
	year  int
}

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

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

	var students []studentFormat
	for i := 0; i < n; i++ {
		student := studentFormat{}
		fmt.Fscanln(reader, &student.name, &student.day, &student.month, &student.year)
		students = append(students, student)
	}
	sort.Slice(students, func(i, j int) bool {
		if students[i].year < students[j].year {
			return true
		} else if students[i].year == students[j].year {
			if students[i].month < students[j].month {
				return true
			} else if students[i].month == students[j].month {
				return students[i].day < students[j].day
			}
		}
		return false
	})
	fmt.Fprintln(writer, students[len(students)-1].name)
	fmt.Fprintln(writer, students[0].name)
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/5635
import sys
import datetime

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    students = []
    for i in range(n):
        name, day, month, year = sys.stdin.readline().split()
        birth = datetime.datetime(int(year), int(month), int(day))
        students.append((birth, name))
    students.sort()
    print(students[-1][1])
    print(students[0][1])
728x90
๋Œ“๊ธ€