Cod sursa(job #2740757)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 14 aprilie 2021 11:20:22
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
typedef long long ll;
int suma;
int magic[31]={0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4,4};
int t,n[105];
void solve()
{
    string s;
    fin>>s;
    n[0]=s.size();
    int rest=0;
    int cif=0;
    bool found=0;
    int nr=0;
    for(int i=1;i<=s.size();i++)
    {
        n[i]=s[i-1]-'0';
        rest=(rest*10+n[i])%20;
        nr=(nr*10)+n[i];
        if(found||nr>=20)
        {
            cif=nr/20;
            nr-=cif*20;
            found=1;
        }
    }
    int val=(4*cif+magic[rest])%10;
    fout<<val<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(0);
    fout.tie(0);
    fin>>t;
    while(t--)
        solve();
    return 0;
}