Cod sursa(job #942097)

Utilizator superman_01Avramescu Cristian superman_01 Data 20 aprilie 2013 19:07:56
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb

//problema facuta in lipsa de ocupatie
#include<cstdio>

#include<cstring>

FILE *f=fopen("cifra.in","r");
FILE *g=fopen("cifra.out","w");

using namespace std;

char s[105];
int tests;
int last[105];

void preprocess ( void )
{
    for(int i(1) ; i <= 100  ; ++i )
    {
        int Sum=1;
      for(int ii(1) ;ii <= i ; ++ii )
         Sum=(Sum*i)%10;
      last[i]=( Sum+last[i-1])%10;
    }


}
int main ( void )
{
    preprocess();
    fscanf(f,"%d",&tests);
    while( tests )
    {
        fscanf(f,"%s",&s);
        int len=strlen(s);
        int numb;
        if( len == 1 )
            numb=s[len-1]-'0';
        else
            numb=(s[len-2]-'0')*10+s[len-1];
        fprintf(g,"%d\n",last[numb]);
        --tests;
    }
    fclose(f);
    fclose(g);
    return 0;
}