Cod sursa(job #2454982)

Utilizator cristi1990anCornea Cristian cristi1990an Data 10 septembrie 2019 16:20:13
Problema Cifra Scor 0
Compilator c-64 Status done
Runda Arhiva de probleme Marime 1.44 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[99999], t[99999];
	unsigned char c[100], s[2];
	FILE* f = fopen("cifra.in", "r"), *g = fopen("cifra.out", "a");
	fgets(c, 100, f);
	sscanf(c, "%u", &T);


	v[0] = 0;


	for (unsigned int j = 1; j <= 100; j++)
		v[j] = v[j - 1] + cifra(j);

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

		fgets(c, 100, f);
		s[0] = c[strlen(c) - 2];
		s[1] = c[strlen(c) - 1];
		
		sscanf(s, "%u", &t[i]);
		
		fprintf(g, "%u\n", v[t[i]]%10);
		fflush(stdout);
	}

	fclose(f);
	fclose(g);
	
	return 0;
}