Cod sursa(job #2355784)

Utilizator stefanut999Paul Colta stefanut999 Data 26 februarie 2019 12:26:20
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
char n[101];
int uc[21]= {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4, 4};
void solve()
{
  if(strlen(n) == 1)
      fout << uc[n[0] - '0'];
  else
    {
      int last2 = n[strlen(n) - 1] - '0' + (n[strlen(n) - 2] - '0') * 10;
      if(last2 <= 20)
        fout << uc[last2];
      else
        {
          int d = last2 / 20;
          fout << (4 * d + uc[last2 - d * 20]) % 10;
        }
    }
}


int main()
{ int t, i;
  fin >> t;
  fin.getline(n,101);

  for(i = 1; i <= t; ++i)
    {
      fin.getline(n,101);
      solve();
      fout <<'\n';
    }
  return 0;
}