Cod sursa(job #1470902)

Utilizator sirbu12Sirbu Claudiu sirbu12 Data 12 august 2015 16:51:26
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <fstream>
using namespace std;
int x;
 int ultimacifra(int x)
    {
        if((x%10==1)||(x%10==5)||(x%10==6))
            return x%10;
        else if(x%10==4)
        {
            if(x%2==0)
                return 6;
            else
                return 4;
        }
        else
        {
            if(x%4==1)
                return x%10;
            if(x%4==2)
                return ((x%10)*(x%10))%10;
            if(x%4==3)
                return ((x%10)*(x%10)*(x%10))%10;
            if(x%4==0)
                return ((x%10)*(x%10)*(x%10)*(x%10))%10;

        }

    }
int main()
{
    int s, i , j , n;
    ifstream f("cifra.in");
    ofstream g("cifra.out");
    f>>n;

    for(i=1; i<=n; i++)
    {
        f>>x;
        s=0;
        for(j=1; j<=x; j++)
        {
            s=s+ultimacifra(j);
            s=s%10;
        }
        g<<s<<endl;

    }

    return 0;
}