Cod sursa(job #1108596)

Utilizator A63N7pTudor Nazarie A63N7p Data 15 februarie 2014 20:55:31
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <cstring>
using namespace std;

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

char a[105];

inline int pow(int, int);

int main(int argc, char *argv[])
{
    int n, x, sol = 0, cnt;
    in >> n;
    in.getline(a, 10);
    for (int i = 1; i <= n; i++) {
        in.getline(a, 105);
        x = strlen(a);
        x = x == 1 ? a[0] - '0' : (a[x - 2] - '0') * 10 + a[x - 1] - '0';
        for (int j = 1; j <= x; j++) {
            cnt = 1;
            if (j % 4 == 0)
                cnt = pow(j, 4);
            else
                for (int k = 1; k <= j % 4; k++)
                    cnt *= j;
            sol += (cnt % 10);
        }
        sol %= 10;
        out << sol << endl;
        sol = 0;
    }
    in.close();
    out.close();
    return 0;
}

inline int pow(int base, int exp)
{
    int aux = 1;
    for (int i = 1; i <= exp; i++)
        aux *= base;
    return aux;
}