Cod sursa(job #754378)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 1 iunie 2012 21:26:59
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<iostream>
#include<fstream>

using namespace std;

ifstream in("nunta.in");
ofstream out("nunta.out");

int a[210], b[210], c[210];

int main()
{
	int N, i, j, t = 0;
	
	in >> N;
	
	if(N <= 3){
		out << N;
		return 0;
	}
	
	a[0] = b[0] = c[0] = 1;
	a[1] = 1; b[1] = c[1] = 2;
	
	for(i = 3; i <= N; ++i, t = 0){
		for(j = 1; j <= c[0] || j <= a[0] || t; ++j, t /= 10)
			c[j] = (t += c[j] + a[j]) % 10;
		
		c[0] = j - 1;
		
		for(j = 0; j <= b[0]; ++j)
			a[j] = b[j];
		
		for(j = 0; j <= c[0]; ++j)
			b[j] = c[j];
	}
	
	for(i = c[0]; i; --i)
		out << c[i];
	
	return 0;
}