Cod sursa(job #324176)

Utilizator dacyanMujdar Dacian dacyan Data 14 iunie 2009 19:33:42
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;

ifstream fin("cifra.in");
ofstream fout("cifra.out");
char ch[102];

int main()
{
    long a[101] = {0};
    long i, j, t, rez, x;
    
    for ( i = 1; i < 101; i++)
    {
       rez = 1;
       for(j = 1; j <= i;j++)
       {
              rez *= i;
              rez = rez % 10;
       }    
       a[i] = (rez  + a[i-1]) %10;
    }
    fin >> t;
    fin.get();
    for ( i = 0 ; i < t; i++)
    {
        fin.getline(ch, 102);
        x = strlen(ch); 
        if ( x > 1)
                j = ( ch[x-2] - '0') * 10 + (ch[x-1] - '0');
        else
                j = ch[x-1] - '0';
        fout << a[j]  << '\n';
    }    
    fin.close();
    fout.close();
    return 0;
}