Cod sursa(job #1687967)

Utilizator vladvlad00Vlad Teodorescu vladvlad00 Data 13 aprilie 2016 10:15:59
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <fstream>
#include <cstring>
#include <algorithm>

using namespace std;

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

char a[10], b[10], c[10];
int n,s,t;

int main()
{
	int i;

	fin >> n;
	if (n < 3) fout << n << '\n';
	else
	{
		a[0] = b[0] = a[1] = 1;
		b[1] = 2;
		while (n-->=3)
		{
			c[0] = b[0];
			for (i = 1; i <= b[0]; i++)
			{
				s = a[i] + b[i] + t;
				c[i] = s % 10;
				t = s / 10;
			}
			while (t)
			{
				c[++c[0]] = t % 10;
				t /= 10;
			}
			memcpy(a, b, sizeof(b));
			memcpy(b, c, sizeof(c));
		}
		for (i = c[0]; i >= 1; i--)
			fout << int(c[i]);
		fout << '\n';
	}
	return 0;
}