Cod sursa(job #2334476)

Utilizator teodorgTeodor G teodorg Data 2 februarie 2019 17:46:01
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int t,n,e,c,k,x[100];
string s;
int main()
{
    for(int i=1;i<20;i++)
    {
        e=i%4;
        c=i%10;
        if(e==0)e=4;
        x[i]=1;
        for(;e;e--)x[i]*=c;
        x[i]%=10;
    }
    for(int i=20;i<100;i++)
        x[i]=x[i-20];
    for(int i=1;i<100;i++)
    {
        x[i]+=x[i-1];
        if(x[i]>9)x[i]-=10;
    }
    f>>t;
    for(;t;t--)
    {
        f>>s;
        n=s.size();
        k=s[n-1]-'0';
        if(n>1)
            k+=10*(s[n-2]-'0');
        g<<x[k]<<'\n';
    }
    return 0;
}