Cod sursa(job #549321)

Utilizator impulseBagu Alexandru impulse Data 8 martie 2011 13:55:05
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 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);
    getline(fin, line);
    ofstream fout("cifra.out");
    for(int c = 0; c < k; c++)
    {
        getline(fin, line);
        if(counter != 0)
        {
            fout<<endl;
            numb[counter] += numb[counter-1];
        }
        numb[counter] += pow(((int)line[line.size() - 1] - 48), (counter + 1) % 4);
        numb[counter] %= 10;
        fout<<numb[counter];
        counter++;
    }
    fin.close();
    fout.close();
    return 0;
}