Cod sursa(job #1468513)

Utilizator mirupetPetcan Miruna mirupet Data 6 august 2015 11:39:29
Problema Cifra Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<cstdio>
#include<cstring>
using namespace std;

char S[100];
int v[] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4};
int N, X, nr, cif;

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

        scanf("%d\n", &N);

        for ( ; N; N--)
        {
            fgets(S, 100, stdin);
            nr = 0;
            cif = strlen(S) - 1;

            if (cif == 1)
                nr = S[(cif) - 1] - 48;
            else
                if (cif == 2)
                    nr = (S[(cif) - 2] - 48) * 10 + S[(cif) - 1] - 48;
            else
                nr = (S[(cif) - 3] - 48) * 100 + (S[(cif) - 2] - 48) * 10 + S[(cif) - 1] - 48;
            printf("%d\n", ((nr / 20) * 4 + v[nr % 20]) % 10);

            //printf("%d\n", nr);
        }
    }