Mai intai trebuie sa te autentifici.
Cod sursa(job #1372912)
Utilizator | Data | 4 martie 2015 15:47:04 | |
---|---|---|---|
Problema | Cifra | Scor | 50 |
Compilator | java | Status | done |
Runda | Arhiva de probleme | Marime | 1.07 kb |
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
int[] table = new int[101];
for (int i=1;i<=100;i++) {
table[i] = (table[i-1] + digit(i)) % 10;
}
Scanner in = new Scanner(new FileInputStream("cifra.in"));
PrintWriter out = new PrintWriter("cifra.out");
int t = in.nextInt();
in.nextLine();
for (int tc = 1; tc <= t; tc++) {
String s = in.nextLine();
int n = 0;
int count = 1;
for (int i=s.length()-1;i>=0 && i>=s.length()-2;i--) {
n = n + (s.charAt(i)-'0')* count;
count*=10;
}
out.println(table[n]);
}
in.close();
out.close();
}
private static int digit(int n) {
int[][] matrix = new int[][] {{0,0,0,0},
{1,1,1,1},
{6,2,4,8},
{1,3,9,7},
{6,4,6,4},
{5,5,5,5},
{6,6,6,6},
{1,7,9,3},
{6,8,4,2},
{1,9,1,9}};
return matrix[n%10][n%4];
}
}