-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDemSoLanXuatHien.java
48 lines (45 loc) · 1.32 KB
/
DemSoLanXuatHien.java
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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package codeptit;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
/**
*
* @author Administrator
*/
public class DemSoLanXuatHien {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int q = t;
while(t-- > 0) {
int n = sc.nextInt();
HashMap<Integer, Integer> mp = new HashMap<>();
int[] a = new int[n];
for(int i=0; i<n; i++){
a[i] = sc.nextInt();
}
for(int x : a){
if(mp.containsKey(x)) {
int freq = mp.get(x);
mp.put(x, freq + 1);
}
else {
mp.put(x, 1);
}
}
System.out.println("Test " + (q - t) + ":");
for(int x : a) {
if(mp.containsKey(x)) {
System.out.println(x + " xuat hien " + mp.get(x) + " lan");
mp.remove(x);
}
}
}
}
}