Cod sursa(job #1185966)

Utilizator MihailPJack ONeill MihailP Data 17 mai 2014 11:28:36
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include<fstream>
#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;
/*int impartire(int A[101],int N)
{
    int i,R=0;
    for(i=1; i<=N; i++)
    {
        R=R*10+A[i];
        A[i]=R/20;
        R=R-A[i]*20;
    }
    return R;

}*/
int main()
{


    fstream f,g;
    f.open("cifra.in",ios::in);
    g.open("cifra.out",ios::out);
    int T,a[101],i,ind,n,R,rez1,rez2,p,rest,j,rez,pret[21];
    char s[101];
    f>>T;
    rez1=7;
    rez2=0;
    for(i=1; i<=20; i++)
    {
        j=0;
        p=1;
        rest=i%4;
        if(rest==0)
            rest=4;
        while(j<rest)
        {
            p=p*(i%10);
            j++;
        }
        rez2=(rez2+p)%10;
        pret[i]=rez2;
    }
    for(ind=1; ind<=T; ind++)
    {
        f>>s;
        n=strlen(s);
        for(i=0; i<n; i++)
            a[i+1]=(int)(s[i])-48;

        R=a[n];

        rez2=pret[R];

        if(a[n-1]%2==1)
            rez2=rez2-7;

       // a[n]=(a[n]+rez2)%10;
        rez=((a[n-1]*7)+rez2)%10;
        g<<rez<<endl;

    }


}