Cod sursa(job #2332994)

Utilizator claudiu.gatinaFMI Claudiu Gatina claudiu.gatina Data 31 ianuarie 2019 16:07:22
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#define NMAX 100010

using namespace std;

fstream f("cifra.in", ios::in);
fstream g("cifra.out", ios::out);

int powResult[10];

int power(int a, int b)
{
  int acc = 1;
  for(int i = 0; i < b; ++i)
    acc *= a;
  return acc;
}

void init()
{
  powResult[0] = 0;
  for(int i = 1; i < 10; ++i)
    powResult[i] = (powResult[i - 1] + power(i, i)) % 10;
}

int main()
{
  init();
  int t;
  string s;
  f >> t;
  for(int i = 0; i < t; ++i)
  {
    f >> s;
    int lastIndice = s.length() - 1;
    int lastDigit = int(s[lastIndice] - '0');
    int preLastDigit = (s.length() >= 2) ? (int(s[lastIndice - 1] - '0')) : 0;
    g << (powResult[lastDigit] + 7 * preLastDigit) % 10 << '\n';

  }
  return 0;
}