Cod sursa(job #1317029)

Utilizator diib1023Cursi FTW diib1023 Data 14 ianuarie 2015 14:44:19
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.85 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];
    short c;

     long long suma = 0 ;
     f.get();
      while(f.get(numar,102))

      {   f.get();
         // cout<<numar<<endl;
            c=(numar[strlen(numar)-2]-48)*10+(numar[strlen(numar)-1]-48);
            if(rez2(c%10)==0)c=c/10;
              else c=c%10;
          suma += rez2(c)%10;
          suma = suma % 10 ;
      }

            g<<suma;

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