Cod sursa(job #27648)

Utilizator Omega91Nicodei Eduard Omega91 Data 6 martie 2007 22:05:47
Problema Cifra Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <string.h>
#include <math.h>
using namespace std;
ifstream f1("cifra.in");
ofstream f2("cifra.out");
int conv(string a) 
{
    int l, aux, i, k;
    aux=0;
    l=a.length();
    for (i=0; i<=l-1; i++)
    {
        aux=aux*10+((int)a[i]-48);
    }
    return aux;
}


int main(void)
{
    const short int uc[20]={1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0};
    const short int s=4;
    string n;
    short int smnf, rasp=0;
    int i, t, asdf;
    f1>>t;
    for (asdf=1; asdf<=t; asdf++)
    {
        rasp=0;
        f1>>n;
        if (n.length()>=2) smnf=conv(n.assign(n.end()-2, n.end()));
        else smnf=conv(n);
        rasp=floor(smnf/20)*s;
        for (i=0; i<(smnf%20); i++)
        {
            rasp+=uc[i];
        }
        f2<<rasp%10<<endl;
    }
    f1.close();
    f2.close();
    return 0; 
}