Cod sursa(job #2521001)

Utilizator alexvali23alexandru alexvali23 Data 10 ianuarie 2020 10:11:38
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int u[101];
int ucif(int n)
{
    int put = n % 4, p = 1, uc = n % 10;
    if(put == 0)put = 4;
    while(put--)
        p *= uc;
    return p % 10;
}
/**
void test()
{
    int s = 0;
    for(int i = 1; i <= 100; i++)
        s += ucif(i);
    g << s % 10;
}
*/
void precalc()
{
    u[0] = 0;
    for(int i = 1; i < 100; i++)
        u[i] = (u[i - 1] + ucif(i))%10;
}
int main()
{
    int t;
    char sir[101];
    precalc();
    f >> t;
    while(t--)
    {
        f >> sir;
        int nrcif = strlen(sir);
        int rest = sir[nrcif - 1] - '0';
        if(nrcif >= 2)
            rest += (sir[nrcif - 2] - '0') * 10;
        g << u[rest] << '\n';
    }
    return 0;
}