Pagini recente » Cod sursa (job #278861) | Cod sursa (job #1201001) | Cod sursa (job #1921039) | Cod sursa (job #2934287) | Cod sursa (job #3210482)
#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;
}