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

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

 

1003๋ฒˆ: ํ”ผ๋ณด๋‚˜์น˜ ํ•จ์ˆ˜

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค 0์ด ์ถœ๋ ฅ๋˜๋Š” ํšŸ์ˆ˜์™€ 1์ด ์ถœ๋ ฅ๋˜๋Š” ํšŸ์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net


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

๐ŸŽจ Go

package main

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

func main() {
	var t int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &t)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	for i := 0 ; i < t; i++ {
		var n int
		fmt.Fscanln(reader, &n)
		zeroCount, oneCount := result(n)
		fmt.Fprintf(writer, "%d %d\n", zeroCount[n], oneCount[n])
	}
}

func result(n int) (zeroCount, oneCount[]int) {
	zeroCount = []int{1, 0}
	oneCount = []int{0, 1}

	if n <= 1 {
		return
	}
	for i := 2; i< n+1; i++ {
		zeroCount = append(zeroCount, zeroCount[i-1]+zeroCount[i-2])
		oneCount = append(oneCount, oneCount[i-1]+oneCount[i-2])
	}
	return
}
728x90
๋Œ“๊ธ€