Cod sursa(job #3229977)

Utilizator popescumalinaPopescu Malina popescumalina Data 18 mai 2024 16:01:38
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("cifra.in");
ofstream g("cifra.out");

int s[30001], n, nr;
char x;

int prelc(int x)
{

    int c = x % 10;
    if(c == 1 || c == 0 || c == 5|| c == 6 || c == 9)
    {
        return c;
    }
    else
    {
        if(c == 4)
        {
            return c * c % 10;
        }
        else
            if(c == 2 || c == 3 || c == 7 || c == 8)
        {
            if(x % 4 == 1)
            {
                return c;
            }
            else
            if(x % 4 == 2)
            {
                return c * c % 10;
            }
            else
            if(x % 4 == 3)
            {
                return c * c * c % 10;
            }
            else
            {
                return c * c * c * c % 10;
            }
        }
    }
}
int main()
{
    f >> n;
    f.get();
    for(int i = 1; i <= 101; i++)
    {
        s[i] = prelc(i);
        s[i] += s[i-1];
        if(s[i] >= 10)
        {
            s[i] %= 10;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        nr = 0;
        f.get(x);
        while(x >='0' && x <='9')
        {
            nr = nr % 10 * 10 + (x - '0');
            f.get(x);
        }
        g << s[nr] << '\n';
    }
    f.close();
    g.close();
    return 0;
}