Cod sursa(job #2167013)

Utilizator danhorea2010Horica danhorea2010 Data 13 martie 2018 19:48:45
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

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

int main()
{
  char s[101];
  int t;
  in>>t;
  int v[101]={0};
  for(int i=1;i<=99;i++)
  {
    v[i] = i;
    for(int j=1;j<i;j++)
    {
      v[i] *= i;
      v[i] %= 10;
    }
    v[i] += v[i-1];
    v[i] %= 10;
  }

  while(t--)
  {
    in>>s;
    int l = strlen(s);
    if(l == 1)
      out<<v[ s[l-1] -'0']<<'\n';
    else out<< v[ (s[l-2]*10 + s[l-1]) - '0']<<'\n';
  }
  return 0;
}