Cod sursa(job #324173)

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

ifstream fin("cifra.in");
ofstream fout("cifra.out");
char ch, c, b;

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;
    for ( i = 0 ; i < t; i++)
    {
        c = fin.get(); 
        b = fin.get();
        if  ( c != '\n' && b != '\n')
                while ( ch != '\n')
                { 
                            ch = fin.get();
                            if ( ch != '\n')
                            {
                                                        b = ch;
                                                        c = b;
                            }
                }        
    
        if ( b != '\n')
                x = (c - '0') * 10 + (b - '0');
        if  ( b == '\n')
                x = c - '0'; 
        fout << a[x]  << '\n';
    }    
    fin.close();
    fout.close();
    return 0;
}