Cod sursa(job #3237608)

Utilizator Mihai_999Diaconeasa Mihai Mihai_999 Data 10 iulie 2024 16:30:59
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>
#define nl '\n'

using namespace std;

ifstream fin("cifra.in");
ofstream fout("cifra.out");

int ans[100], coef[100];
string s;

void solve()
{
    fin >> s;
    int n = s.size(), x;
    if (n == 1)
        x = s[0]-'0';
    else
        x = (s[n-2]-'0')*10+(s[n-1]-'0');
    fout << ans[x] << nl;
}

void preluc()
{
    for (int i = 1; i < 100; i++)
        coef[i] = 1;
    for (int i = 1; i < 100; i++)
    {
        for (int j = 1; j < 100; j++)
            coef[j] = (coef[j]*j)%10;
        ans[i] = (ans[i-1]+coef[i])%10;
    }
    return;
}

int main()
{
    preluc();
    int t;
    fin >> t;
    while (t--)
        solve();
    return 0;
}