Cod sursa(job #2166967)

Utilizator danhorea2010Horica danhorea2010 Data 13 martie 2018 19:39:28
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[102];
  int t;
  in>>t;
  int v[102]={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;
    if(strlen(s) == 1)
      out<<v[ s[strlen(s)-1] -'0']<<'\n';
    else out<< v[ s[strlen(s)-2]*10 + s[strlen(s)-1] - '0']<<'\n';
  }
  return 0;
}