-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrypt1.java
More file actions
81 lines (76 loc) · 1.87 KB
/
crypt1.java
File metadata and controls
81 lines (76 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.BitSet;
import java.util.StringTokenizer;
/*
ID: mryuan01
LANG: JAVA
TASK: crypt1
*/
public class crypt1 {
private static BitSet bs = new BitSet(10);
private static int[] nums = null;
static{
bs.clear();
}
private static int numSolve = 0;
public static boolean numInRight(int num, int digits){
if(digits < 2 || digits > 4)
return false;
if(digits == 2 && (num < 10 || num >= 100))
return false;
if(digits == 3 && (num < 100 || num >= 1000))
return false;
if(digits == 4 && (num < 1000 || num >= 10000))
return false;
int k = 0;
while(num != 0){
k = num % 10;
if(bs.get(k) == false)
return false;
num /= 10;
}
return true;
}
public static void getM2(int start, int M1, int M2){
if(start >= 2){
if(numInRight(M2, 2) && numInRight(M1 * M2, 4))
numSolve++;
return ;
}
for(int i = 0; i < nums.length; i++){
if(numInRight(M1 * nums[i], 3)){
getM2(start+1, M1, M2 * 10 + nums[i]);
}
}
}
public static void getM1(int start, int M1){
if(start >= 3){
if(numInRight(M1, 3))
getM2(0, M1, 0);
return ;
}
for(int i = 0; i < nums.length; i++){
getM1(start+1, M1 * 10 + nums[i]);
}
}
public static void main(String[]args) throws IOException{
BufferedReader f = new BufferedReader(new FileReader("crypt1.in"));
// input file name goes above
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("crypt1.out")));
int num = Integer.parseInt(f.readLine().trim());
nums = new int[num];
StringTokenizer st = new StringTokenizer(f.readLine());
for(int i = 0; i < num; i++){
nums[i] = Integer.parseInt(st.nextToken());
bs.set(nums[i]);
}
getM1(0, 0);
out.println(numSolve);
out.close();
}
}