Pagini recente » Cod sursa (job #1266992) | Cod sursa (job #1484670) | Cod sursa (job #3155183) | Cod sursa (job #2893518) | Cod sursa (job #1317027)
#include <iostream>
#include <fstream>
#include <cmath>
#include <string.h>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
long rez2(long x)
{ long y,h,rez;
y=x;
x=x % 10;
if (x==0) rez=0;
if (x==1) rez=1;
if (x==2)
{
h=y % 4;
if (h==1) rez=2;
if (h==2) rez=4;
if (h==3) rez=8;
if (h==0) rez=6;
};
if (x==3)
{
h=y % 4;
if (h==1) rez=3;
if (h==2) rez=9;
if (h==3) rez=7;
if (h==0) rez=1;
};
if (x==4)
{
h=y % 2;
if (h==1) rez=4;
if (h==0) rez=6;
};
if (x==5) rez=5;
if (x==6) rez=6;
if (x==7)
{
h=y % 4;
if (h==1) rez=7;
if (h==2) rez=9;
if (h==3) rez=3;
if (h==4) rez=1;
};
if (x==8)
{
h=y % 4;
if (h==1) rez=8;
if (h==2) rez=4;
if (h==3) rez=2;
if (h==0) rez=6;
};
if (x==9)
{
h=y % 2;
if (h==1) rez=9;
if (h==0) rez=1;
};
return rez;
};
int main()
{
ifstream f("cifra.in");
ofstream g("cifra.out");
long t,i ;
f >> t ;
char numar[102];
short c;
long long suma = 0 ;
f.get();
while(f.get(numar,102))
{ f.get();
// cout<<numar<<endl;
c=numar[strlen(numar)-1]-48;
suma += rez2(c)%10;
suma = suma % 10 ;
}
g<<suma;
f.close();
g.close();
return 0;
}