Cod sursa(job #904954)

Utilizator alexblackFMI - Dumitrache Alexandru alexblack Data 5 martie 2013 08:57:09
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream in ("cifra.in");
ofstream out("cifra.out");
int const N=10;
int const M=105;
int t,n,mat[N][N];
char x[M];
int pow(int x, int y)
{
    int rez=1;
    for(int i=1;i<=y;i++)
        rez*=x;
    return rez;
}
void completez()
{
    for(int i=1;i<10;i++)
        for(int j=1;j<5;j++)
        {
            mat[i][j]=pow(i,j);
            mat[i][j]%=10;
        }
    for(int i=1;i<10;i++)
        mat[i][0]=mat[i][4];
}
void afis()
{
   for(int i=0;i<10;i++)
   {
        for(int j=0;j<4;j++)
            out<<mat[i][j]<<" ";
        out<<"\n";
   }
}
void pars()
{
    int lg=strlen(x);
    n=x[lg-1]-'0';
    if(lg>1)
        n=(x[lg-2]-'0')*10+n;
}
void calculez()
{
    int rez=0;
    pars();
    for(long long i=1;i<=n;i++)
    {rez+=mat[i%10][i%4];rez%=10;}
    out<<rez<<",";
}
int main()
{
    completez();    in>>t;
    for(int i=1;i<=t;i++)
        //out<<100+i<<"\n";
        {in>>x; calculez();}
    //afis();
    return 0;
}