-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_pair_items_TWU.java
More file actions
86 lines (62 loc) · 2.1 KB
/
print_pair_items_TWU.java
File metadata and controls
86 lines (62 loc) · 2.1 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
81
82
83
84
85
86
//主要是想利用FHM算法中的2-items的TWU值
//下面实现的是:将嵌套的map表示的值填入二维数组,并打印二维数组
package com.helloHKTK;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class Main {
class Pair{
int item = 0;
int utility = 0;
}
public static void main(String[] args) {
Map<Integer, Map<Integer, Long>> mapFMAP;
mapFMAP = new HashMap<Integer, Map<Integer, Long>>();
// row1
Map<Integer, Long> mp1= new HashMap<Integer, Long>();
mp1.put(2, (long) 35);
mp1.put(3, (long) 55);
mp1.put(4, (long) 33);
mp1.put(5, (long) 47);
mapFMAP.put(1, mp1);
//row2
Map<Integer, Long> mp2= new HashMap<Integer, Long>();
mp2.put(3, (long) 54);
mp2.put(4, (long) 45);
mp2.put(5, (long) 54);
mapFMAP.put(2, mp2);
//row3
Map<Integer, Long> mp3= new HashMap<Integer, Long>();
mp3.put(4, (long) 53);
mp3.put(5, (long) 76);
mapFMAP.put(3, mp3);
//row4
Map<Integer, Long> mp4= new HashMap<Integer, Long>();
mp4.put(5, (long) 45);
mapFMAP.put(4, mp4);
for (Map.Entry<Integer, Map<Integer, Long>> entry : mapFMAP.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
System.out.println("-----------------------");
// 以下才是重点,将嵌套的map表示的值填入二维数组,并打印二维数组
int i,j;
int row_num=5,column_num=5;//0,1,2,3,4
long[][] arr = new long[row_num][column_num];
for (Map.Entry<Integer, Map<Integer, Long>> entry : mapFMAP.entrySet())
{
//System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
Map<Integer, Long> mp= new HashMap<Integer, Long>();
mp =entry.getValue();
for(Map.Entry<Integer, Long> entry1 : mp.entrySet())
{
arr[entry.getKey()-1][entry1.getKey()-1]=entry1.getValue();
}
}
for(i=0;i<row_num;i++)
{
for (j=0;j<column_num;j++)
System.out.print(arr[i][j]+" ");
System.out.print("\n");
}
}
}