Cod sursa(job #165289)

Utilizator lookyLucaci Alexandru Adrian looky Data 25 martie 2008 20:05:35
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <fstream.h>

ifstream f ("cifra.in");
ofstream g ("cifra.out");

int t,suma;
long huge n;
int uc[8][10];


void calc (long huge k)
{for (int i=1;i<=k;i++)
  {int rest;
   rest=k%10;
  if (rest==1)
   suma+=1;
   else
    if (rest==2 || rest==4 || rest==6 || rest==8)
     suma+=uc[k][k%5];
     else
      if (rest==3 || rest==7 || rest==9)
       suma+=uc[k][k%10];
  if (suma>=10) suma=suma%10;
  }
 g<<suma<<endl;
}


void citire()
{f>>t;
 for (int i=0;i<n;i++)
  {f>>n;
   calc(n);
  }
}

void initializare()
{
uc[2][1]=2;
uc[2][2]=4;
uc[2][3]=6;
uc[2][4]=8;
uc[2][0]=0;

uc[3][1]=3;
uc[3][2]=6;
uc[3][3]=9;
uc[3][4]=2;
uc[3][5]=5;
uc[3][6]=8;
uc[3][7]=1;
uc[3][8]=4;
uc[3][9]=7;
uc[3][0]=0;

uc[4][1]=4;
uc[4][2]=8;
uc[4][3]=2;
uc[4][4]=6;
uc[4][0]=0;

uc[5][1]=5;
uc[5][0]=0;

uc[6][1]=6;
uc[6][2]=2;
uc[6][3]=8;
uc[6][4]=4;
uc[6][0]=0;

uc[7][1]=7;
uc[7][2]=4;
uc[7][3]=1;
uc[7][4]=8;
uc[7][5]=5;
uc[7][6]=2;
uc[7][7]=9;
uc[7][8]=6;
uc[7][9]=3;
uc[7][0]=0;

uc[8][1]=8;
uc[8][2]=6;
uc[8][3]=4;
uc[8][4]=2;
uc[8][0]=0;

uc[9][1]=9;
uc[9][2]=8;
uc[9][3]=7;
uc[9][4]=6;
uc[9][5]=5;
uc[9][6]=4;
uc[9][7]=3;
uc[9][8]=2;
uc[9][9]=1;
uc[9][0]=0;
}

void main()
{initializare();
 citire();
}