Cod sursa(job #1687945)

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

using namespace std;

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

void aduna(char*x, char*y,char*z);

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

int main()
{
	int i;

	fin >> n;
	if (n < 3) fout << n << '\n';
	else
	{
		a[0] = b[0] = a[1] = 1;
		b[1] = 2;
		for (i = 3; i <= n; i++)
		{
			aduna(a, b, c);
			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;
}

void aduna(char*x, char*y, char*z)
{
	int i, s, t = 0;

	z[0] = y[0];
	for (i = 1; i <= y[0]; i++)
	{
		s = x[i] + y[i] + t;
		z[i] = s % 10;
		t = s / 10;
	}
	while (t)
	{
		z[++z[0]] = t % 10;
		t /= 10;
	}
}