Cod sursa(job #549360)

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

int numb[30000], k;

int reducePower(int pw)
{
    int n = pw % 4;
    if(n == 0)
        return 4;
    return n;
}


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