Cod sursa(job #1790833)

Utilizator Rodik_RodyRodica Vasilescu Rodik_Rody Data 28 octombrie 2016 19:17:28
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.51 kb
#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int t,s,i,x;
int cif(int x, int p)
{
    if(x==0||x==1||x==5||x==6)
        return x;
    if(x==2)
        if(p%4==1)
          return 2;
         else
            if (p%4==2)
                  return 4;
             else
                if(p%4==3)
                   return 6;
                 else
                    return 8;
     if(x==3)
        if(p%4==1)
          return 3;
         else
            if (p%4==2)
                  return 9;
             else
                if(p%4==3)
                   return 7;
                 else
                    return 1;
     if(x==4)
        if(p%2==1)
          return 4;
         else
            return 6;
     if(x==7)
        if(p%4==1)
          return 7;
         else
            if (p%4==2)
                  return 9;
             else
                if(p%4==3)
                   return 3;
                 else
                    return 1;
     if(x==8)
        if(p%4==1)
          return 8;
         else
            if (p%4==2)
                  return 4;
             else
                if(p%4==3)
                   return 2;
                 else
                    return 6;
     if(x==9)
        if(p%2==1)
          return 9;
         else
           return 1;
}
int main()
{
       f>>t; s=0;
    for(i=1;i<=t;i++){
        f>>x;
        s=(s+cif(x,x))%10;
       g<< s<<'\n';
    }
    return 0;
}