Cod sursa(job #2215433)
| Utilizator | Data | 22 iunie 2018 09:39:59 | |
|---|---|---|---|
| Problema | Cifra | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include<fstream>
#include<cmath>
using namespace std;
int T, lastDigit, preLastDigit;
string N;
int sum[2][10] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 0, 1, 7, 0, 6, 1, 7, 4, 8, 7};
int main()
{
ifstream fin("cifra.in");
ofstream fout("cifra.out");
fin>>T;
for(;T > 0; --T) {
fin>>N;
lastDigit = *(N.end() - 1) - '0';
preLastDigit = N.length() > 1 ? *(N.end() - 2) - '0' : 0;
fout<<(((preLastDigit * 7) %10 + sum[preLastDigit%2][lastDigit])%10)<<"\n";
}
return 0;
}