Cod sursa(job #549304)

Utilizator impulseBagu Alexandru impulse Data 8 martie 2011 13:26:03
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include<fstream>
#include<math.h>
#include<string>
using namespace std;

int numb[30000], k;

int UltimaCifraAPuterii(int num, int pw)
{
    int u;
    u = num % 10;
    int a = num % 10;
    for(int c = 1; c <= pw; c++)
    {
        u *= a;
        u %= 10;
    }
    return u;
}

int main()
{
    ifstream fin("cifra.in");
    int counter = 0;
    fin>>k;
    string line;
    line.reserve(101);
    while(!fin.eof())
    {
        getline(fin, line);
        for(int c = line.size() - 1; c >= 0; c--)
        {
            if(line[c] != ' ')
            {
                if(counter != 0)
                    numb[counter] += numb[counter-1];
                numb[counter] += pow(((int)line[c] - 48), counter + 1);
                //numb[counter] %= 10;
                counter++;
                break;
            }
        }
    }
    fin.close();
    ofstream fout("cifra.out");
    for(int c = 0; c < k; c++)
        fout<<numb[c]%10<<endl;
    fout.close();
    return 0;
}