Cod sursa(job #1443114)

Utilizator karlaKarla Maria karla Data 26 mai 2015 23:22:07
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <stdio.h>
#include <string.h>

using namespace std;

FILE*f=fopen("cifra.in","r"),*g=fopen("cifra.out","w");

int c[21] = {0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0}, t, s[21];
char n[110];

void sume()
{
    for(int i = 0; i <= 20; i++)
    {
        c[i] = (c[i-1] + c[i])% 10;
    }
}

int main()
{
    sume();
    int l,x,y;
    fscanf(f,"%d",&t);
    for(int i = 1; i <= t; i++)
    {
        fscanf(f,"%s\n",n);
        l = strlen(n);
        if(l >= 3)
            x = n[l-1] - '0' + (n[l-2] - '0') * 10 + (n[l-3] - '0') * 100;
        else if(l == 2)
            x = n[l-1] - '0' + (n[l-2] - '0') * 10;
        else x = n[l-1] - '0';
        x = x % 100;
        if(x < 20) fprintf(g,"%d\n",c[x]);
        else if(x >= 20 && x < 40) fprintf(g,"%d\n",(c[x-20]+4)%10);
        else if(x >= 40 && x < 60) fprintf(g,"%d\n",(c[x-40]+8)%10);
        else if(x >= 60 && x < 80) fprintf(g,"%d\n",(c[x-60]+2)%10);
        else if(x >= 80 && x < 100) fprintf(g,"%d\n",(c[x-80]+6)%10);

    }
    return 0;
}