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

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

 

2303๋ฒˆ: ์ˆซ์ž ๊ฒŒ์ž„

N๋ช…์ด ๋ชจ์—ฌ ์ˆซ์ž ๊ฒŒ์ž„์„ ํ•˜๊ณ ์ž ํ•œ๋‹ค. ๊ฐ ์‚ฌ๋žŒ์—๊ฒŒ๋Š” 1๋ถ€ํ„ฐ 10์‚ฌ์ด์˜ ์ˆ˜๊ฐ€ ์ ํ˜€์ง„ ๋‹ค์„ฏ ์žฅ์˜ ์นด๋“œ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ ์ค‘ ์„ธ ์žฅ์˜ ์นด๋“œ๋ฅผ ๊ณจ๋ผ ํ•ฉ์„ ๊ตฌํ•œ ํ›„ ์ผ์˜ ์ž๋ฆฌ ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ํฐ ์‚ฌ๋žŒ์ด ๊ฒŒ์ž„์„ ์ด

www.acmicpc.net


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

๐ŸŽจ Go

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

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

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

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

	var cards = make([][]int, n)
	for i := 0; i < n; i++ {
		cards[i] = make([]int, 5)
		for j := 0; j < 5; j++ {
			fmt.Fscanf(reader, "%d ", &cards[i][j])
		}
	}
	fmt.Fprintln(writer, getWinner(cards))
}

func getWinner(cards [][]int) int {
	var maxSum, winner int
	var sumOne, sumTwo, sumThree int
	for i := 0; i < len(cards); i++ {
		for j := 0; j < 5; j++ {
			sumOne = cards[i][j]
			for k := j + 1; k < 5; k++ {
				sumTwo = sumOne + cards[i][k]
				for l := k + 1; l < 5; l++ {
					sumThree = sumTwo + cards[i][l]
				}
				if maxSum <= sumThree%10 {
					maxSum = sumThree % 10
					winner = i + 1
				}
			}
		}
	}
	return winner
}

๐ŸŽจ Python3

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

def get_winnder(cards):
    max_sum, winner = 0, 0
    sum_one, sum_two, sum_three = 0, 0, 0
    for i in range(len(cards)):
        for j in range(5):
            sum_one = cards[i][j]
            for k in range(j+1, 5):
                sum_two = sum_one + cards[i][k]
                for l in range(k+1, 5):
                    sum_three = sum_two + cards[i][l]
                if max_sum <= sum_three % 10:
                    max_sum = sum_three % 10
                    winner = i + 1
    return winner

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    cards = []
    for i in range(n):
        cards.append(list(map(int, sys.stdin.readline().split())))
    print(get_winnder(cards))
728x90
๋Œ“๊ธ€