Cod sursa(job #2065735)

Utilizator perhapss44Saraev Stefan perhapss44 Data 14 noiembrie 2017 09:09:26
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

int main()
{
    ifstream in ("cifra.in");
    ofstream out ("cifra.out");
    int n,p,t,s;
    int r[4][10]={0,1,6,1,6,5,6,1,6,1,
                  0,1,2,3,4,5,6,7,8,9,
                  0,1,4,9,6,5,6,9,4,1,
                  0,1,8,7,4,5,6,3,2,9};
    char nr[102];
    ///n la puterea p
    ///este acelasi cu (ultima cifra a lui n) la p
    ///este acelasi cu (ultima cifra a lui n) la (p%4)
    ///(n%10) la (p%4)

    //for(int i=0;i<=3;i++)
    //    for (int j=1;j<=9;j++) cout<<r[i][j]<<" ";
    //cin>>n;
    in>>t;
    for(int i=1;i<=t;i++){
        in>>nr;
        p=strlen(nr);
        if (p>1)
            n=(nr[p-2]-48)*10+(nr[p-1]-48);
        else if (p==1)
            n=nr[p-1]-48;
        s=0;
        for (int j=1;j<=n%100;j++){
            s=s+r[j%4][j%10];
        }
        out<<s%10<<endl;
    }


    return 0;
}