Cod sursa(job #664811)

Utilizator BugirosRobert Bugiros Data 20 ianuarie 2012 21:06:27
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.6 kb
#include <cstdio>
#include <cstring>
using namespace std;

const int MAXN = 111;

int v[111];
char n[MAXN];
int ln;

//int preprocesare(int nr)
//{
//    int cif = 0,c_cif;
//    for (int i = 1;i <= nr;++i)
//    {
//        c_cif = 1;
//        for (int j = 1;j <= i;++j)
//        {
//            c_cif *= i;
//            c_cif %= 100;
//        }
//        cif += c_cif;
//        cif %= 100;
//    }
//    return cif;
//}

void citire()
{
    int nr_teste;
    freopen ("cifra.in","r",stdin);
    freopen ("cifra.out","w",stdout);
    scanf ("%d\n",&nr_teste);
    for (int i = 1;i <= nr_teste;++i)
    {
        gets(n);
        ln = strlen(n);
        if (ln == 1)
            printf ("%d\n",v[n[0] - '0'] % 10);
        else printf ("%d\n",(v[(n[ln - 2] - '0') * 10 + (n[ln - 1] - '0')] % 10));
        scanf("\n");
    }
}

void preprocesare()
{
    v[1] = 1;
    v[2] = 5;
    v[3] = 32;
    v[4] = 88;
    v[5] = 13;
    v[6] = 69;
    v[7] = 12;
    v[8] = 28;
    v[9] = 17;
    v[10] = 17;
    v[11] = 28;
    v[12] = 84;
    v[13] = 37;
    v[14] = 53;
    v[15] = 28;
    v[16] = 44;
    v[17] = 21;
    v[18] = 45;
    v[19] = 24;
    v[20] = 24;
    v[21] = 45;
    v[22] = 29;
    v[23] = 96;
    v[24] = 72;
    v[25] = 97;
    v[26] = 73;
    v[27] = 76;
    v[28] = 12;
    v[29] = 81;
    v[30] = 81;
    v[31] = 12;
    v[32] = 88;
    v[33] = 1;
    v[34] = 37;
    v[35] = 12;
    v[36] = 48;
    v[37] = 65;
    v[38] = 69;
    v[39] = 28;
    v[40] = 28;
    v[41] = 69;
    v[42] = 33;
    v[43] = 40;
    v[44] = 36;
    v[45] = 61;
    v[46] = 57;
    v[47] = 20;
    v[48] = 76;
    v[49] = 25;
    v[50] = 25;
    v[51] = 76;
    v[52] = 72;
    v[53] = 45;
    v[54] = 1;
    v[55] = 76;
    v[56] = 32;
    v[57] = 89;
    v[58] = 73;
    v[59] = 12;
    v[60] = 12;
    v[61] = 73;
    v[62] = 17;
    v[63] = 64;
    v[64] = 80;
    v[65] = 5;
    v[66] = 21;
    v[67] = 44;
    v[68] = 20;
    v[69] = 49;
    v[70] = 49;
    v[71] = 20;
    v[72] = 36;
    v[73] = 69;
    v[74] = 45;
    v[75] = 20;
    v[76] = 96;
    v[77] = 93;
    v[78] = 57;
    v[79] = 76;
    v[80] = 76;
    v[81] = 57;
    v[82] = 81;
    v[83] = 68;
    v[84] = 4;
    v[85] = 29;
    v[86] = 65;
    v[87] = 48;
    v[88] = 44;
    v[89] = 53;
    v[90] = 53;
    v[91] = 44;
    v[92] = 80;
    v[93] = 73;
    v[94] = 69;
    v[95] = 44;
    v[96] = 40;
    v[97] = 77;
    v[98] = 21;
    v[99] = 20;
    v[100] = 20;
}

int main()
{
    preprocesare();
    citire();
    return 0;
}