Cod sursa(job #267546)

Utilizator emberromionescustefan emberrom Data 27 februarie 2009 17:10:43
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
ifstream fi ("cifra.in");
ofstream fo ("cifra.out");
int s,t,x,y,r,i,nrcif,yp[10]={7,1,5,2,8,3,9,2,8,7}, yi[10]={5,1,7,0,4,9,5,2,6,5};
char n[101],a[2], b[2];
int main()
{fi>>t;
 for(i=1; i<=t; i++)
   {fi>>n;nrcif=strlen(n); a[0]=n[nrcif-1];b[0]=n[nrcif-2];
     x=atoi(a); y=atoi(b);
    if(y%2==0) r=yp[x]; else r=yi[x];
    s=(y+1)/2*7+y/2*5+r; s=s%10; fo<<s<<'\n';
    };
fi.close(); fo.close();
return 0;
}