Cod sursa(job #2740754)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 14 aprilie 2021 11:16:06
Problema Cifra Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
typedef long long ll;
ll suma;
ll magic[31]={0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4,4};
ll t,n[105];
ll imp()
{
    ll cif=0;
    bool found=0;
    ll nr=0;
    for(int i=1;i<=n[0];i++)
    {
        nr=(nr*10)+n[i];
        if(found||nr>=20)
        {
            cif=nr/20;
            nr%=20;
            found=1;
        }
    }
    return cif;
}
void solve()
{
    string s;
    fin>>s;
    n[0]=s.size();
    ll rest=0;
    for(int i=0;i<s.size();i++)
    {
        n[i+1]=s[i]-'0';
        rest=(rest*10+n[i+1])%20;
    }
    ll val=(4*imp()+magic[rest])%10;
    fout<<val<<'\n';
}
int main()
{
    fin>>t;
    while(t--)
        solve();
    return 0;
}