Pagini recente » Cod sursa (job #578268) | Cod sursa (job #2441509) | Cod sursa (job #2745681) | Cod sursa (job #3142367) | Cod sursa (job #1219290)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define FIN "cifra.in"
#define FOUT "cifra.out"
#define ASCII(c) (int)c
int main() {
int t,i,k,n,rez,aux;
char x[100];
FILE *in, *out;
in = fopen(FIN, "rt");
out = fopen(FOUT, "wt");
fscanf(in, "%d", &t);
for(i=0; i < t; i++){
fscanf(in, "%s", x);
if(strlen(x) > 1){
n = (x[strlen(x) - 2] - ASCII('0'))*10 + x[strlen(x) - 1] - ASCII('0');
} else {
n = x[0] - ASCII('0');
}
for(k=1,rez=0; k <= n; k++){
if(k%10 == 1){
rez += 1;
} else if (k%10 == 2) {
aux = k%4;
if(aux == 1) {
rez += 2;
} else if(aux == 2) {
rez += 4;
} else if(aux == 3) {
rez += 8;
} else {
rez += 6;
}
} else if (k%10 == 3) {
aux = k%4;
if(aux == 1) {
rez += 3;
} else if(aux == 2){
rez += 9;
} else if(aux == 3){
rez += 7;
} else {
rez += 1;
}
} else if (k%10 == 4) {
aux = k%2;
if(aux == 1){
rez += 4;
} else {
rez += 6;
}
} else if (k%10 == 5) {
rez += 5;
} else if (k%10 == 6) {
rez += 6;
} else if (k%10 == 7) {
aux = k%4;
if(aux == 1){
rez += 7;
} else if (aux == 2){
rez += 9;
} else if (aux == 3){
rez += 3;
} else {
rez += 1;
}
} else if (k%10 == 8) {
aux = k%4;
if(aux == 1){
rez += 8;
} else if (aux == 2){
rez += 4;
} else if (aux == 3){
rez += 2;
} else {
rez += 6;
}
} else if (k%10 == 9) {
aux = k%2;
if(aux == 1){
rez += 9;
} else {
rez += 1;
}
}
rez %= 10;
}
fprintf(out, "%d\n", rez%10);
}
return 0;
}