Cod sursa(job #2207951)

Utilizator radu.hobincuRadu Hobincu radu.hobincu Data 27 mai 2018 16:08:52
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <cstdio>
#include <cstring>
#include <cstdlib>

int main() {
//     freopen("cifra.in", "r", stdin);
//     freopen("cifra.out", "w", stdin);
    char number[102];




    int matrix[10][4] = {{0, 0, 0, 0},
                    {1, 1, 1, 1},
                    {6, 2, 4, 8},
                    {1, 3, 9, 7},
                    {6, 4, 6, 4},
                    {5, 5, 5, 5},
                    {6, 6, 6, 6},
                    {1, 7, 9, 3},
                    {6, 8, 4, 2},
                    {1, 9, 1, 9}
    };

    int values[100];
    values[0] = 0;
    for(int i = 1; i < 100; i++) {
        values[i] = values[i - 1] + matrix[i % 10][i % 4];
        values[i - 1] = values[i - 1] % 10;
//        printf("%d -> %d \n", i-1, values[i-1]);
    }
    values[99] = values[99] % 10;
//    return 0;

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

    while(tests--) {
        scanf("%s", number);
        int length = strlen(number);
        int value;
        if(length > 2) {
            value = atoi(number + strlen(number) - 2);
        } else {
            value = atoi(number);
        }
//        printf("Value: %d\n", value);
        printf("%d\n", values[value]);
    }
    return 0;
}