Cod sursa(job #165314)

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

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

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


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


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

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

uc[3][1]=3;
uc[3][2]=9;
uc[3][3]=7;
uc[3][0]=1;

uc[4][1]=4;
uc[4][0]=6;

uc[7][1]=7;
uc[7][2]=9;
uc[7][3]=3;
uc[7][0]=1;

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

uc[9][1]=9;
uc[9][0]=1;
}

int main()
{initializare();
 citire();
 return 1;
}