Cod sursa(job #3367832)

Utilizator rapidu36Victor Manz rapidu36 Data 11 octombrie 2026 11:39:52
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <cstring>

using namespace std;

const int T = 20;
const int NC = 100;

int uc_s[T];
char numar[NC+1];

int main() {
    for (int i = 1; i < T; i++) {
        int cif =  i % 10;
        int exp = i % 4;
        if (exp == 0) {
            exp = 4;
        }
        int putere = 1;
        for (int j = 0; j < exp; j++) {
            putere *= cif;
        }
        putere %= 10;
        uc_s[i] = (uc_s[i-1] + putere) % 10;
    }
    ifstream fin("cifra.in");
    ofstream fout("cifra.out");
    int t;
    fin >> t;
    for (int i = 0; i < t; i++) {
        fin >> numar;
        int nr_cif = strlen(numar);
        int n = numar[nr_cif-1] - '0';
        if (nr_cif > 1) {
            n = (numar[nr_cif-2] - '0') * 10 + n;
        }
        int nr_grupe_20 = n / 20;
        int rest_grupa = n % 20;
        fout << (nr_grupe_20 * 4 + uc_s[rest_grupa]) % 10 << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}