Cod sursa(job #1434600)

Utilizator msschFMI - Enache Alexandru Madalin mssch Data 10 mai 2015 21:51:50
Problema Cifra Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int a[100];
int main()
{
    int t,i,n;
    char v[102];
    FILE*f=fopen("cifra.in", "r");
    FILE*g=fopen("cifra.out", "w");
    fscanf(f, "%d\n", &t);
    a[0]=0;
    for(i=1;i<=99;i++)
        {if(i%10==0) a[i]=0;
        else
        if(i%10==1) a[i]=1;
        else
        if(i%10==2)
            {if(i%4==0) a[i]=6;
                else if(i%4==1) a[i]=2;
                else if(i%4==2) a[i]=4;
                else a[i]=8;}
        else
        if(i%10==3)
            {if(i%4==0) a[i]=1;
                else if(i%4==1) a[i]=3;
                else if(i%4==2) a[i]=9;
                else a[i]=7;}
        else
        if(i%10==4)
            if(i%2==0) a[i]=6;
                else a[i]=4;
        else if(i%10==5) a[i]=5;
        else if(i%10==6) a[i]=6;
        else
        if(i%10==7)
            {if(i%4==0) a[i]=1;
                else if(i%4==1) a[i]=7;
                else if(i%4==2) a[i]=9;
                else a[i]=3;}
        else
        if(i%10==8)
            {if(i%4==0) a[i]=6;
                else if(i%4==1) a[i]=8;
                else if(i%4==2) a[i]=4;
                else a[i]=2;}
        else
               if(i%2==0) a[i]=1;
                else a[i]=9;
        a[i]=(a[i]+a[i-1])%10;}
    for(i=0;i<t;i++)
        {fgets(v, 101, f);
        n=strlen(v)-1;
        if(n>1)
            fprintf(g,"%d\n", a[(v[n-2]-'0')*10+(v[n-1]-'0')]);
            else fprintf(g,"%d\n", a[v[n-1]-'0']);}
    fclose(f);
    fclose(g);
    return 0;
}