안녕 세상아,

[c++/백준] 1003 피보나치 함수 본문

백준

[c++/백준] 1003 피보나치 함수

돈 많은 백수가 되고싶다 2023. 5. 7. 00:06

https://www.acmicpc.net/problem/1003

 

1003번: 피보나치 함수

각 테스트 케이스마다 0이 출력되는 횟수와 1이 출력되는 횟수를 공백으로 구분해서 출력한다.

www.acmicpc.net

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t;
	cin >> t;

	int zero[45] = {};
	int one[45] = {};

	zero[0] = 1;
	zero[1] = 0;
	one[0] = 0;
	one[1] = 1;

	for (int i = 2; i < 45; i++) {
		zero[i] = zero[i - 1] + zero[i - 2];
		one[i] = one[i - 1] + one[i - 2];
	}
	for (int i = 0; i < t; i++) {
		int x;
		cin >> x;

		cout << zero[x] << " " << one[x] << endl;
	}
}

'백준' 카테고리의 다른 글

[c++/백준] 2606 바이러스  (1) 2023.05.08
[c++/백준] 1966 프린터 큐  (1) 2023.05.08
[c++/백준] 9095 1, 2, 3 더하기  (0) 2023.05.05
[c++/백준] 1929 소수 구하기  (0) 2023.05.05
[c++/백준] 1463 1로 만들기  (0) 2023.05.04