Cod sursa(job #759648)

Utilizator SchumiDumitru Andrei Georgian Schumi Data 18 iunie 2012 21:12:38
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <string>

using namespace std;

string nr;
int t, n, dim;
const int rest[] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4};

int main()
{
    int i;
    ifstream f("cifra.in");
    ofstream g("cifra.out");
    f >> t;
    for(i = 1; i <= t; ++i) {
        f >> nr;
        dim = nr.size();
        if(dim == 1)
            n = nr[dim - 1] - '0';
        else if(dim == 2)
            n = nr[dim - 1] - '0' + (nr[dim - 2] - '0') * 10;
        else
            n = nr[dim - 1] - '0' + (nr[dim - 2] - '0') * 10 + (nr[dim - 3] - '0') * 100;
        g << ((4 * ((n / 20) % 10) % 10) + rest[n % 20]) % 10 << "\n";
    }

    return 0;
}