Cod sursa(job #568137)

Utilizator XladhenianGrigorita Vlad-Stefan Xladhenian Data 30 martie 2011 20:44:16
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>
#include <string.h>

using namespace std;

/*

 1 ^ 1   ==  1
 2 ^ 2   ==  4
 3 ^ 3   ==  7
 4 ^ 4   ==  6
 5 ^ 5   ==  5
 6 ^ 6   ==  6
 7 ^ 7   ==  3
 8 ^ 8   ==  6
 9 ^ 9   ==  9
10 ^ 10  ==  0
11 ^ 11  ==  1
12 ^ 12  ==  6
13 ^ 13  ==  3
14 ^ 14  ==  6
15 ^ 15  ==  5
16 ^ 16  ==  6
17 ^ 17  ==  7
18 ^ 18  ==  4
19 ^ 19  ==  9
20 ^ 20  ==  0

---------------
            94


*/

int main(void)
{
 fstream f1("cifra.in",ios::in);
 fstream f2("cifra.out",ios::out);
 int a = 0;
 char N_[150];
 char *PP = N_;
 N_[0] = '0';
 PP++;
 int N = 0;
 int T = 0;
 int NR = 0;
 int l = 0;
 int i;
// long n[] = {1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0};
// long n[20] = {0,1,5,12,18,23,29,32,38,47,47,48,54,57,63,68,74,81,85,94};
 int n[110] = {0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4};
 for (i = 20;i < 100;i = i + 1)
  {
   n[i] = (n[i % 20] + 4 * (i / 20)) % 10;
  }
 f1 >> T;
 for (a = 0;a < T;a++)
  {
   f1 >> PP;
   l = strlen(N_);
   N = (N_[l - 1] - 48) + ((N_[l - 2] - 48) * 10);
//   NR = 4 * (N / 20);
//   f2 << ((NR + n[N % 20]) % 10) << endl;
   f2 << n[N] << "\n";
  }
 f1.close();
 f2.close();
 return 0;
}