Cod sursa(job #2392361)

Utilizator hurjuiAlexandru12Hurjui Alexandru-Mihai hurjuiAlexandru12 Data 29 martie 2019 22:02:28
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.55 kb
//
//  main.cpp
//  Alex
//
//  Created by Hurjui Alexandru Mihai on 02/11/2018.
//  Copyright © 2018 Hurjui Alexandru Mihai. All rights reserved.
//

#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;
}