Cod sursa(job #2934901)

Utilizator matthriscuMatt . matthriscu Data 6 noiembrie 2022 11:59:57
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <bits/stdc++.h>
using namespace std;

#define NMAX 105

int ans[] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7};

int main() {
	freopen("cifra.in", "r", stdin);
	freopen("cifra.out", "w", stdout);

	int t;
	scanf("%d", &t);

	char n[NMAX];

	while (t--) {
		scanf("%s", n);
		int l = strlen(n);
		if (l == 1)
			printf("%d\n", ans[n[l - 1] - '0']);
		else
			printf("%d\n", (7 * (n[l - 2] - '0') + ans[n[l - 1] - '0']) % 10);
	}
}