Cod sursa(job #1105164)

Utilizator TeofilosTeofil Teofilos Data 11 februarie 2014 15:52:57
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>
#include <cstring>
#define ccc 101

using namespace std;

int x,v[ccc],t;
long l;
string s;

ifstream in("cifra.in");
ofstream out("cifra.out");

int main(){
    for (int i=1; i<=100; i++){
        x=1;
        for (int j=1; j<=i; j++) x=(x*i)%10;
        v[i]=(v[i-1]+x)%10;
    }
    in >> t;
    for (int i=1; i<=t; i++){
        in >> s;
        l=s.size();
        if (l==1) out << v[s[l-1]-48] << "\n";
        else out << v[(s[l-2]-48)*10 + s[l-1]-48] << "\n";
    }

    return 0;
}