-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
67 lines (57 loc) · 1.33 KB
/
test.java
File metadata and controls
67 lines (57 loc) · 1.33 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
import java.util.Random;
public class test{
static int SIZE = 11881376; // 26*26*26*26*26
static int SIZE1 = 100000; // 26*26*26*26*26
int len = 5;
static int[] data =new int[SIZE];
static char[] str = new char[5];
static int getNum(char strtemp[]){
int val =0;
for(int i =0;i< 5;i++)
val = val *26 + strtemp[i]-'a';
data[val]++;
return data[val];
}
static int getchar(char strtemp[]){
int val = 0;
for (int i =0 ;i< 5 ;i++){
val += val *26 +strtemp[i]-'a';
val%=SIZE1;
}
return val;
}
public static int getKey(int val){
return val%(SIZE1+10);
}
public static void main(String[] args) {
char [] a = {'e','j','v','s','p','r'};
char [] b = {'a','a','a','a','c'};
//int fs = getchar(a);
System.out.println(873%100);
System.out.println(getchar(a));
System.out.println(getKey(getchar(b)));
int flag =0;
for(int i=0;i<a.length;i++)
{
if(a[i]!=b[i]){
flag =1;
break;
}
}
if(flag == 0 )
System.out.println(" == ");
// TODO Auto-generated method stub
long start=System.currentTimeMillis();
Random ramdon = new Random();
int max = 0;
for(int i = 0; i < 100000; i++){
for(int j = 0; j < 5; j++){
str[j] = (char) (ramdon.nextInt(26) + 'a');
}
int temp = getNum(str);
if(temp>max)
max= temp;
}
System.out.println(max);
}
}