Cod sursa(job #1317025)

Utilizator diib1023Cursi FTW diib1023 Data 14 ianuarie 2015 14:36:13
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.75 kb
#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];
    char last,l1;
    short c;

     long long suma = 0 ;
     f.get();
      for (i=1;i<=t;i++)

      {   f.get(numar,102);f.get();
            c=numar[strlen(numar)-1]-48;
          suma += rez2(c)%10;
          suma = suma % 10 ;
      }

            g<<suma;

    f.close();
    g.close();
    return 0;
}