Cod sursa(job #1925936)

Utilizator waren4Marius Radu waren4 Data 13 martie 2017 20:55:03
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream f("cifra.in"); ofstream g("cifra.out");
int i,n,cif,a[105]; string b;
int cifra(int x)
{
    int c,y;
    y=x;
    x=x%10;
    if(x==0) c=0;
    if(x==1) c=1;
    if(x==2)
    {
        if (y%4==0) c=6;
        if (y%4==1) c=2;
        if (y%4==2) c=4;
        if (y%4==3) c=8;
    }
    if(x==3)
    {
        if (y%4==0) c=1;
        if (y%4==1) c=3;
        if (y%4==2) c=9;
        if (y%4==3) c=7;
    }
    if(x==4)
    {
        if (y%2==0) c=6;
        if (y%2==1) c=4;
    }
    if(x==5) c=5;
    if(x==6) c=6;
    if(x==7)
    {
        if (y%4==0) c=1;
        if (y%4==1) c=7;
        if (y%4==2) c=9;
        if (y%4==3) c=3;
    }
    if(x==8)
    {
        if (y%4==0) c=6;
        if (y%4==1) c=8;
        if (y%4==2) c=4;
        if (y%4==3) c=2;
    }
    if(x==9)
    {
        if (y%2==0) c=1;
        if (y%2==1) c=9;
    }
    return c;

}
int main()
{
    f>>n;
    a[0]=0;
    cif=0;
    for(i=1;i<=100;i++)
    {
        a[i]=(a[i-1]+cifra(i))%10;
    }
    for(i=1;i<=n;i++)
    {
        int nr;
        f>>b;
        nr=b.length();
        nr--;
        if (nr==0)
        {
            g<<a[b[nr]-'0']<<'\n';
        }
        else
        {
            g<<a[(b[nr-1]-'0')*10+b[nr]-'0']<<'\n';
        }
    }
    return 0;
}