Cod sursa(job #1671605)

Utilizator ArkinyStoica Alex Arkiny Data 1 aprilie 2016 22:12:46
Problema Sarpe Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include<fstream>
#include<algorithm>
using namespace std;

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

typedef unsigned short Huge[100000];

Huge h1;


void Mult(Huge H, unsigned long X)
{
	int i;
	unsigned long T = 0;

	for (i = 1;i <= H[0];i++)
	{
		H[i] = H[i] * X + T;
		T = H[i] / 10;
		H[i] = H[i] % 10;
	}
	while (T)
	{
		H[++H[0]] = T % 10;
		T /= 10;
	}
}

int main()
{
	char c;
	int nr = 0;
	while (in >> c)
		h1[++nr] = c-'0';
	h1[0] = nr;
	for (int i = 1;i <= h1[0] / 2;++i)
		swap(h1[i], h1[nr - i + 1]);

	if (h1[0] == 1 && h1[1] == 1)
		out << 2;
	else
	{
		Mult(h1, 4);

		for (int i = h1[0];i >= 1;--i)
			out << h1[i];

	}

	return 0;
}