Cod sursa(job #793198)

Utilizator tudorv96Tudor Varan tudorv96 Data 2 octombrie 2012 11:37:14
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>
#include <cstring>

using namespace std;

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

int a[100];
int ucif;
int n;
int number;
int s;
int x;
char citeste [102];

int main ()
{
    fin >> n;
    fin.ignore(1);
    for (int i = 1 ; i < 100 ; ++i)
    {
        a[i] = i % 10;
        for (int j = 1; j < ( (i - 1) % 4) + 1; ++j)
        {
            a[i] = (a[i] * (i % 10)) % 10;
        }
    }
    for (int i = 0; i < n; ++i)
    {
        s = 0;
        fin.getline (citeste, 102);
        x = strlen (citeste) - 1;
        if (x > 0)
        {
            number = (citeste [x - 1] - '0') * 10 + (citeste [x] - '0');
        }
        else
            number = citeste [x] - '0';
        for (int j = 0; j <= number; ++j)
            s = (s + a [j]) % 10;
        fout << s << '\n';
    }
    fin.close ();
    fout.close ();
    return 0;
}