Cod sursa(job #2460308)

Utilizator bori2000Fazakas Borbala bori2000 Data 23 septembrie 2019 12:54:04
Problema Cifra Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;

int utszj(int x)
{
    if(x%10==1) return 1;

    if(x%10==2 and x%4==2) return 4;
    if(x%10==2 and x%4==0) return 6;

    if(x%10==3 and x%4==1) return 3;
    if(x%10==3 and x%4==3) return 7;

    if(x%10==4) return 6;

    if(x%10==5) return 5;

    if(x%10==6) return 6;

    if(x%10==7 and x%4==1) return 7;
    if(x%10==7 and x%4==3) return 3;

    if(x%10==8 and x%4==2) return 4;
    if(x%10==8 and x%4==0) return 6;

    if(x%10==9) return 9;

    if(x%10==0) return 0;
}

int utszj_2(int a)
{
    if(a==1) return 1;
    long long akt = 0;
    akt = pow(a, a);
    akt%=10;

    return (akt + utszj_2(a-1));
}

int main()
{
    ifstream f("cifra.in");
    ofstream g("cifra.out");

    int t;
    f>>t;
    //cout<<t<<endl;

    string s;
    getline(f, s);
    int  m, ered;

    //tomb generalasa
    int v[100];
    v[1]=1;
    for(int i=2; i<=99; i++)
    {
        v[i]=v[i-1]+utszj(i);
        v[i]%=10;
    }

    for(int i=1; i<=t; i++)
    {
        getline(f, s);

        if(s.length()>=2){
            s=s.substr(s.length()-2, 2);
            m=(s[0]-48)*10+(s[1]-48);
        }
        else m=s[0]-48;

        /*ered = 0;
        ered+=m/20*4;
        ered%=10;
        while(m%20!=0)
        {
            ered+=utszj(m);
            ered%=10;
            m--;
        }*/
        g<<v[m]<<endl;
    }


    return 0;
}