Study with book/Algorithms

[백준]피보나치 함수


백준저지

[피보나치 함수]https://www.acmicpc.net/problem/1003


• 5분만에 푼문제이다. 왜 정답률이 39%인지 모르겠다.

• 그냥 주어진 문제를 그대로 코딩하면 끝...


#include <iostream>
using namespace std;
int ansZ, ansO;
int fib(int n) {
	if (n == 0) {
		ansZ++; 	return 0; 
	} else if (n == 1) {
		ansO++; return 0;
	} else
		return fib(n - 1) + fib(n - 2);
}
int main(void) {
	int cnt; cin >> cnt;
	for (int i = 0; i < cnt; i++) {
		int in; cin >> in;
		fib(in); cout << ansZ << " " << ansO << endl;
		ansZ = 0; ansO = 0;
	}
	return 0;
}

'Study with book > Algorithms' 카테고리의 다른 글

개선된 피보나치 함수 구현  (0) 2017.06.02
[백준]동전 0  (0) 2017.03.23
[백준]K번째 수  (0) 2017.01.13
[백준]이진탐색트리  (2) 2017.01.12
[백준]트리  (2) 2017.01.02