Cod sursa(job #1729087)

Utilizator danyvsDan Castan danyvs Data 14 iulie 2016 10:34:13
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <cstring>

using namespace std;

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

const int NMax = 101;

int a[NMax], n;
char s[NMax];

void Precalculare()
{
    unsigned long long sum, i, j, c;
    sum = 0;
    for (i = 1; i <= 100; ++ i)
        {
         c = 1;
         for (j = 1; j <= i; ++ j)
            c = (c * (i % 10)) % 10;
         sum = (sum + c) % 10;
         a[i] = sum;
        }
}

int main()
{
    int i;
    Precalculare();
    fin >> n;
    for (i = 1; i <= n; ++ i)
        {
         fin >> s;
         if (strlen(s) == 1)
            fout << a[s[strlen(s) - 1] - '0'] << "\n";
         else
            fout << a[(s[strlen(s) - 2] - '0') * 10 + (s[strlen(s) - 1] - '0')] << "\n";
        }
    fin.close();
    fout.close();
    return 0;
}