Pagini recente » Cod sursa (job #531009) | Cod sursa (job #2059927) | Cod sursa (job #1317564) | Cod sursa (job #2537589) | Cod sursa (job #2631369)
#include <fstream>
#include <cstring>
using namespace std;
ifstream f ( "cifra.in" );
ofstream g ( "cifra.out" );
char S[10001];
int sum[] = { 0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 6, 6 };
int main()
{ int T, i;
f >> T;
for ( i = 1; i <= T; i++ ){
f >> ( S + 1 );
int n = strlen ( S + 1 );
int a = 0, b = 0, c = 0, d = S[n] - '0';
if ( n > 1 )
a = S[n - 1] - '0';
b = a - a % 2;
if ( n > 2 )
b += ( S[n - 2] - '0' ) % 2 * 10;
b = b / 2;
c = 8 * b % 10;
d += ( a % 2 ) * 10;
g << ( c + sum[d] ) % 10 << '\n';
}
return 0;
}