Cod sursa(job #2554002)

Utilizator mariuscomoMarius Iulian Comorasu mariuscomo Data 22 februarie 2020 14:31:57
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int n, i, s, j, numar;
int ultimacifra (int a)
{if (a % 10 == 0 || a % 10 == 1 || a % 10 == 5 || a % 10 == 6)
    return a % 10;
if (a % 10 == 4 || a % 10 == 9)
    {if(a % 10 == 4)
        if(a % 2 == 0)
            return 6;
        else
            return 4;
    if(a % 10 == 9)
        if(a % 2 == 0)
             return 1;
        else
            return 9;
    }
if (a % 10 == 2)
    {if (a % 4 == 1)
        return 2;
    if (a % 4 == 2)
        return 4;
    if (a % 4 == 3)
        return 8;
    if (a % 4 == 4)
        return 6;
    }
if (a % 10 == 3)
    {if(a % 4 == 1)
        return 3;
    if (a % 4 == 2)
        return 9;
    if (a % 10 == 3)
        return 7;
    if (a % 10 == 4)
        return 1;
}
if (a % 10 == 7)
    {if (a % 4 == 1)
        return 7;
    if (a % 4 == 2)
        return 9;
    if (a % 4 == 3)
        return 3;
    if  (a % 4 == 4)
        return 1;
}
if (a % 10 == 8)
    {if(a % 4 == 1)
        return 8;
    if(a % 4 == 2)
        return 4;
    if(a % 4 == 3)
        return 2;
    if(a % 4 == 4)
        return 6;
    }
}


int suma(int x)
{s = 0;
for(i = 1; i <= x; i++)
    {s = s + ultimacifra(i);
    s = s % 10;
    }
return s;
}


int main()
{f >> n;
for(j = 1; j <= n; j++)
    {f >> numar;
    g << suma(numar) << endl;
    }
    return 0;
}