Cod sursa(job #1150011)

Utilizator Andrei2016Baciu Andrei Andrei2016 Data 22 martie 2014 15:02:32
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
4
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
#include<fstream>
#include<cstring>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int n,nr,L,a[105];
char s[105];
int putere(int k)
{
    int i,sol=1;
    for (i=1;i<=k;++i)
        sol*=k, sol%=10;
    return sol;
}
void calcul()
{
    int i;
    for (i=1;i<=100;++i)
        a[i]=a[i-1]+putere(i), a[i]%=10;
}
int main()
{
    calcul();
    f>>n; f.get();
    for (int i=1;i<=n;++i)
    {
        f.getline(s,105);
        L=strlen(s);
        if (L>1) nr=(s[L-2]-'0')*10+s[L-1]-'0';
        else nr=s[L-1]-'0';
        g<<a[nr]<<'\n';
    }
    return 0;
}