Pagini recente » Cod sursa (job #703056) | Cod sursa (job #2002269) | Cod sursa (job #2565192) | Cod sursa (job #123771) | Cod sursa (job #7990)
Cod sursa(job #7990)
#include <fstream.h>
long int n,k;
int mat[4][10],uc,r,i,T,j;
int calc()
{
uc=0;
k= n / 10;r= n % 10;
if ((k%2)==1) uc=5;
for (j=1;j<=r;j++)
uc=uc+mat[j%4][j];
return uc%10;
}
void citire()
{
ifstream f;
f.open("cifra.in",ios::in);
ofstream g;
g.open("cifra.out",ios::out);
f>>T;
for (i=1;i<=T;i++)
{
f>>n;
g<<calc()<<endl;
}
}
int main()
{
mat[0][0]=0;mat[0][1]=1;mat[0][2]=6;mat[0][3]=0;mat[0][4]=6;mat[0][5]=5;mat[0][6]=6;mat[0][7]=0;mat[0][8]=6;mat[0][9]=9;
mat[1][0]=0;mat[1][1]=1;mat[1][2]=0;mat[1][3]=3;mat[1][4]=6;mat[1][5]=5;mat[1][6]=6;mat[1][7]=7;mat[1][8]=0;mat[1][9]=9;
mat[2][0]=0;mat[2][1]=1;mat[2][2]=4;mat[2][3]=0;mat[2][4]=6;mat[2][5]=5;mat[2][6]=6;mat[2][7]=0;mat[2][8]=4;mat[2][9]=9;
mat[3][0]=0;mat[3][1]=1;mat[3][2]=0;mat[3][3]=7;mat[3][4]=6;mat[3][5]=5;mat[3][6]=6;mat[3][7]=3;mat[3][8]=0;mat[3][9]=9;
citire();
return 0;
}