Cod sursa(job #2454952)

Utilizator cristi1990anCornea Cristian cristi1990an Data 10 septembrie 2019 15:29:50
Problema Cifra Scor 60
Compilator c-64 Status done
Runda Arhiva de probleme Marime 1.6 kb
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

unsigned int cifra(unsigned int n)
{
	unsigned int m = n % 10;

	switch (m)
	{
	case 0: return 0; 
	case 1: return 1;
	case 2: 
	{
		switch (n % 4)
		{
		case 0: return 6;
		case 1: return 2;
		case 2: return 4;
		case 3: return 8;
		}
	}
	case 3:
	{
		switch (n % 4)
		{
		case 0: return 1;
		case 1: return 3;
		case 2: return 9;
		case 3: return 7;
		}
	}
	case 4:
	{
		switch (n % 2)
		{
		case 0: return 6;
		case 1: return 4;
		}
	}
	case 5: return 5;
	case 6: return 6;
	case 7: 
		switch (n % 4)
		{
		case 0: return 1;
		case 1: return 7;
		case 2: return 9;
		case 3: return 3;
		}
	case 8:
		switch (n % 4)
		{
		case 0: return 6;
		case 1: return 8;
		case 2: return 4;
		case 3: return 2;
		}
	case 9:
		switch (n % 2)
		{
		case 0: return 1;
		case 1: return 9;
		}

	}
	return 0;
}

int main()
{
	unsigned int T, v[99909], t[99990], max=0, aux;
	unsigned char c[2];
	FILE* f = fopen("cifra.in", "r");
	fscanf(f, "%u", &T);

	c[0] = '0';
	v[0] = 0;
	c[1] = fgetc(f);

	for (unsigned int i = 1; i <= T; i++)
	{
		t[i] = 0;
		do
		{
			c[1] = fgetc(f); 

			if ((c[1] == '\n')||(c[1]<'0')||(c[1]>'9'))
				break;

			sscanf(c, "%u", &aux);

			t[i] = (t[i] * 10 + aux) % 100;

		} while (1);
			
		if (max < t[i])
			max = t[i];
	}

	for (unsigned int i = 1; i <= max+1; i++)
		v[i] = (v[i - 1] + cifra(i))%10;

	f = fopen("cifra.out", "a");
	
	for (unsigned int i = 1; i <= T; i++)
	{
		fprintf(f, "%u\n", v[t[i]]);
		fflush(stdout);
	}

	fclose(f);
	
	return 0;
}