Cod sursa(job #1691015)

Utilizator AlexutAlex Calinescu Alexut Data 16 aprilie 2016 16:53:16
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <cstring>
using namespace std;
char k[110];
int main()
{
    ifstream cin ("cifra.in");
    ofstream cout ("cifra.out");
    int t,i,n;
    cin>>t;
    cin.get();
    for(i=1;i<=t;i++)
    {
        cin.getline(k,105);
        n=strlen(k);
        int x=0,s=0;
        if(n>=2)
         {x=k[n-2]-'0';
         s=(7*x/10)%10;}
        int y=k[n-1]-'0';
        if(y==1)
        {
         s+=1;
        }
        if(y==2)
        {
            s+=5;

        }
        if(y==3)
            s+=2;
        if(y==4)
            s+=8;

        if(y==5)
            s+=3;
        if(y==6)
            s+=9;
        if(y==7)
            s+=2;
        if(y==8)
            s+=8;
        if(y==9)
            s+=7;
        s=s%10;
        cout<<s<<endl;
    }

    return 0;
}