Cod sursa(job #1015664)

Utilizator sebinsteanuDumitriu Sebastian sebinsteanu Data 24 octombrie 2013 22:12:01
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <math.h>
#include <sstream>
#include<string.h>
using namespace std;

ifstream in("cifra.in");
ofstream out("cifra.out");
unsigned c[29999],s;
int mat[10][10];

void formare()
{
    int i,j=1;
    while(j<=9)
    {
        for(int i=1;i<=4;i++)
            if(j==5)
                mat[j][i]=5;
            else
                mat[j][i]=(int)pow(j,i)%10;
        j++;
    }
    for(j=0;j<=9;j++)
        mat[j][0]=mat[j][4];

}

int sum(int x)
{
    int s=0,i;
    for (i=1;i<=x;i++)
        s=s+mat[i%10][i%4];
    return s%10;
}

int main ()
{
    int j,t,n,mat[10][10];
    formare();


    for(int i=0;i<=9;i++)
    {   for(int j=0;j<=4;j++)
            out<<mat[i][j]<<" ";
        out<<"\n";
    }
    out<<"\n\n";

    in>>t;
    for(n=0;n<t;n++)
    {
        in>>c[n];
        out<<sum(c[n])<<"\n";
    }
    in.close();
    out.close();
    return 0;
}