Cod sursa(job #2772648)

Utilizator Gabryel9898Bizdoc Vasile Gabriel Gabryel9898 Data 2 septembrie 2021 07:51:58
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <iostream>
#include <chrono>
#include <fstream>
#include <unordered_map>
#include <cstdlib>

using namespace std;
using namespace chrono;

int process(int n) {
    int final = 0;

    for (int i = 1; i <= n; ++i) {
        int tmp = i;
        for (int j = 1; j < i; ++j) {
            tmp *= i;
            tmp %= 10;
        }
        final += tmp;
        final = final % 10;
    }
    return final % 10;
}

void cifra() {
    ifstream f1;
    ofstream f2;

//    f1.open("../in.txt");
//    f2.open("../out.txt");
    f1.open("cifra.in");
    f2.open("cifra.out");

    int number_of_numbers;

    f1 >> number_of_numbers;

    vector<int> numbers(number_of_numbers);

//    {
//        const int MAX = 10000;
//        char buffer[MAX];
//
//        for (int i = 0; i < number_of_numbers; ++i) {
//            f1 >> buffer;
//            int length = strlen(buffer);
//            int res = buffer[length - 1] - '0';
//            numbers.push_back(res);
//        }
//    }

    for (auto &n: numbers) {
        f1 >> n;
    }


    for (auto n: numbers) {
        f2 << process(n) << '\n';
    }
}


int main() {
    auto start = high_resolution_clock::now();

    cifra();

    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<milliseconds>(stop - start);
    cout << endl << "[time]:" << duration.count() << endl;
    return 0;
}