Cod sursa(job #977928)

Utilizator alexflav23alfl23 alexflav23 Data 27 iulie 2013 01:37:13
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>


int sum = 0;
int* predefs = new int[101];

int getSum(char* number) {
    int length = std :: strlen(number);
    int lastDigit = number[length - 1] - '0';
    if (length == 1)
    {
        return predefs[lastDigit] % 10;
    }
    else
    {
        int penultimate = number[length - 2] - '0';
        return predefs[penultimate * 10 + lastDigit] % 10;
    }
};

int cifra() {
    
    std :: ifstream fin("cifra.in");
    std :: ofstream fout("cifra.out");
    int limit = 0;
    predefs[0] = 0;
    
    for (int i = 1; i <= 100; i++)
    {
        int copy = i % 10;
        sum += pow(copy, copy);
        sum = sum % 100;
        predefs[i] = sum;
    }
    
    fin >> limit;
    
    char line[101];
    
    for (int i = 0; i < limit; i++)
    {
        fin >> line;
        fout << getSum(line) << std :: endl;
    }
    
    delete [] predefs;
    
    fin.close();
    fout.close();
    
    return 0;
};