Cod sursa(job #3210482)

Utilizator Real_agdAlexandru George Daniel Real_agd Data 6 martie 2024 12:31:41
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <fstream>

using namespace std;

int main(){
    int T, N, i, q, S=0, lastDigit;
    int V2[2]={6,9};
    int V4[4][4]={
            {3, 7, 7, 3},
            {6, 2, 4, 8},
            {6, 8, 4, 2},
            {7, 3, 1, 7}
        };


    ifstream cifra_in("cifra.in");
    cifra_in>>T;
    int Vsolutie[T];
    for(i=0; i<T; i++){ // problema nr T
        cifra_in>>N;
        for(q=1; q<=N; q++){
            lastDigit=q%10;
            if(lastDigit==1 || lastDigit==5 || lastDigit==6 || lastDigit==0)
                S+=lastDigit;
            else if(lastDigit==4 ||lastDigit==9)
                S+=V2[lastDigit%2];
            else 
                S+=V4[lastDigit%7][q%4];
        }
        Vsolutie[i]=S%10;
        S=0;
    }

    // moves the vector into the *out* file
    ofstream cifra_out("cifra.out");
    for(i=0; i<T; i++)
        cifra_out<<Vsolutie[i]<<"\n";

    return 0;
}