Cod sursa(job #2404443)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 12 aprilie 2019 19:50:44
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <fstream>

#include <cstring>

using namespace std;

 

ifstream fin("cifra.in");

ofstream fout("cifra.out");

 

int main()

{

    char x[101];

    int t, i, nr;

    int a[101];

    for (i = 1; i<=100; i++)

    {

        if (i%10 == 1)

            a[i] = 1;

        else if (i%10 == 2)

        {

            if (i% 4 == 0)

                a[i] = 6;

            else

                a[i] = 4;

        }

        else if (i%10 == 3)

        {

            if (i%4 == 1)

                a[i] = 3;

            else

                a[i] = 7;

        }

        else if (i%10 == 4)

            a[i] = 6;

        else if (i%10 == 5)

            a[i] = 5;

        else if (i%10 == 6)

            a[i] = 6;

        else if (i%10 == 7)

        {

            if (i%4 == 1)

                a[i] = 7;

            else if (i%4 == 3)

                a[i] = 3;

        }

        else if (i%10 == 8)

        {

            if (i%4==0)

                a[i] = 6;

            else

                a[i] = 4;

        }

        else if (i%10 == 9)

            a[i] = 9;

        else if (i%10 == 0)

            a[i] = 0;

    }

    a[0] = 0;

    for (i = 1; i<=100; i++)

        a[i] = (a[i-1] + a[i])%10;

    fin >> t;

    for (i = 1; i<=t; i++)

    {

        fin >> x;

        if (strlen(x) > 1)

            nr = (x[strlen(x)-2]-48)*10 + x[strlen(x)-1]-48;

        else

            nr = x[strlen(x)-1]-48;

        fout << a[nr] << '\n';

    }

    return 0;

}