Cod sursa(job #2340103)

Utilizator PatrascuAdrian1Patrascu Adrian Octavian PatrascuAdrian1 Data 9 februarie 2019 19:40:06
Problema Cifra Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <cstring>

using namespace std;

ifstream f("cifra.in");
ofstream g("cifra.out");

char s[101];
int x,r,nr,j,i,n,k,sum,c;
const int a[]= {1,5,2,8,3,9,2,8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4,4 };

int main()
{
    f >> n,f.get();
    for(i = 1; i <= n ; ++i)
    {
        f.getline(s,sizeof(s));
        x = strlen(s);
        if(x>=2)
            x = (s[x-2]-48)*10 + s[x-1]-48;
        else
            x = s[x-1]-48;
        if(x % 20 == 0)
            r = 19;
        else
            r = x % 20 - 1;
        c = x / 20;
        g << (a[r]+c*4)%10 << '\n';
    }
}