Cod sursa(job #1914373)

Utilizator adi1607Ciurea Adi adi1607 Data 8 martie 2017 16:41:07
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <cstdio>
#include<cstring>
#define limit 100
using namespace std;

int main()
{
    freopen("cifra.in","r",stdin);
    freopen("cifra.out","w",stdout);
    int ans[limit+5];
    char s[limit+5];
    int q,n,lenght;
    char ch;
    ans[1]=1;
    for(int i=2; i<=limit; ++i)
    {
        ans[i]=1;
        for(int j=1; j<=i; ++j)
        {
            ans[i]=(ans[i]*i)%10;
        }
        ans[i]=(ans[i-1]+ans[i])%10;

    }
    scanf("%d\n",&q);
    int h=1;
    for(h=1;h<=q;++h)
    {
        scanf("%s\n",&s);
        lenght=strlen(s);
        if(lenght==1)
        n=s[lenght-1]-'0';
        else
        n=(s[lenght-2]-'0')*10+(s[lenght-1]-'0');
        printf("%d\n",ans[n]);
    }
    return 0;
}