Cod sursa(job #1966549)

Utilizator matystroiaStroia Matei matystroia Data 15 aprilie 2017 12:56:34
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <cstring>
using namespace std;

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

int n, v[105];

int f(int x)
{
    int s=0;
    for(int i=1;i<=x;++i)
    {
        int p=i%10, uc=i%10;
        for(int j=0;j<i-1;++j)
        {
            p*=i%10;
            uc=p%10;
            p%=10;
        }
        s=(s+uc)%10;
    }
    return s;
}

int main()
{
    for(int i=1;i<=99;++i)
        v[i]=f(i);

    fin>>n;
    for(int i=0;i<n;++i)
    {
        char s[105];
        fin>>s;
        if(strlen(s)==1)
            fout<<v[s[0]-'0']<<'\n';
        else
            fout<<v[(s[strlen(s)-2]-'0')*10+s[strlen(s)-1]-'0'];
    }
    return 0;
}