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

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

 

2670๋ฒˆ: ์—ฐ์†๋ถ€๋ถ„์ตœ๋Œ€๊ณฑ

์ฒซ์งธ ์ค„์€ ๋‚˜์—ด๋œ ์–‘์˜ ์‹ค์ˆ˜๋“ค์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง€๊ณ , ๊ทธ ๋‹ค์Œ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ˆ˜๊ฐ€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๋“ค์–ด ์žˆ๋‹ค. N์€ 10,000 ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋‹ค. ์‹ค์ˆ˜๋Š” ์†Œ์ˆ˜์  ์ฒซ์งธ์ž๋ฆฌ๊นŒ์ง€ ์ฃผ์–ด์ง€๋ฉฐ, 0.0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜

www.acmicpc.net


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

๐ŸŽจ Go

// https://www.acmicpc.net/problem/2670
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 realNumbers = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanln(reader, &realNumbers[i])
	}
	for i := 1; i < n; i++ {
		mul := realNumbers[i-1] * realNumbers[i]
		if realNumbers[i] < mul { // ์ด์ „์˜ ๊ฐ’๊ณผ ํ˜„์žฌ ๊ฐ’์„ ๊ณฑํ•œ ๊ฐ’์ด์ด ํ˜„์žฌ ๊ฐ’๋ณด๋‹ค ๋” ํฌ๋ฉด ๊ณฑํ•œ ๊ฐ’์œผ๋กœ ๊ฐฑ์‹ 
			realNumbers[i] = mul
		}
	}
	var answer float64
	for i := 0; i < n; i++ {
		if answer < realNumbers[i] {
			answer = realNumbers[i]
		}
	}
	fmt.Fprintf(writer, "%.3f\n", answer)
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    real_numbers = []
    for i in range(n):
        real_numbers.append(float(sys.stdin.readline()))
    for i in range(1, n):
        mul = real_numbers[i-1] * real_numbers[i]
        real_numbers[i] = max(mul, real_numbers[i])
    answer = max(real_numbers)
    print("{:.3f}".format(answer))
728x90
๋Œ“๊ธ€