Cod sursa(job #1842224)

Utilizator MihalachiRazvanMihalachi Razvan MihalachiRazvan Data 6 ianuarie 2017 17:49:37
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <string>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
long int a[10],b[10],n,t,p;
string s;
int main()
{
a[1]=1;
a[2]=5;
a[3]=2;
a[4]=8;
a[5]=3;
a[6]=9;
a[7]=2;
a[8]=8;
a[9]=7;
b[1]=1;
b[2]=7;
b[3]=0;
b[4]=6;
b[5]=1;
b[6]=7;
b[7]=4;
b[8]=8;
b[9]=7;
fin>>t;
for(int i=1;i<=t;i++)
    {

        fin>>s;
        p=s.length();
    if(p==1)
        fout<<a[int(s[0]-'0')]<<endl;
    else if(int(s[p-2]-'0')%2==0)
    {
        n=int(s[p-2]-'0')*7+a[int(p-1)-'0'];
        fout<<n%10<<endl;}
        else
        {
        n=int(s[p-2]-'0')*7+b[int(s[p-1]-'0')];
        fout<<n%10<<endl;
        }
    }


    return 0;
}