Cod sursa(job #2140218)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 23 februarie 2018 08:14:22
Problema Cifra Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream in ("cifra.in");
ofstream out ("cifra.out");

int lastcif(int n ,int k){
  if(k == 0)
    return 1;
  else{
    k %= 4;
    if(k == 0)
      k = 4;
    int result = 1;
    for(int i = 1 ; i <= k ;i++){
      result *= n;
      result %= 10;
    }
    return result;
  }
}
int const nmax = 100;
char line[5 + nmax];

int main()
{
  int t , n;
  in>>t;
  line[0] = '0';
  for(int testcase = 1 ;testcase <= t ;testcase++){
    in>>(line + 1);
    n = strlen(line + 1);
    int k = (line[n - 1] - '0') * 10 + (line[n] - '0');
    int result = 0;
    for(int i = 1 ; i <= k ;i++){
      result += lastcif(i , i);
      result %= 10;
    }
    out<<result<<'\n';
  }
  return 0;
}