-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.4-Codare semnal imagine.java
38 lines (31 loc) · 1.16 KB
/
4.4-Codare semnal imagine.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
import java.util.*;
public class Andrei{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
ArrayList<Integer> v1=new ArrayList<Integer>();
ArrayList<Integer> v2=new ArrayList<Integer>();
int[][] imag=new int[m][n];
for(int i=0;i<m;i++)
for(int j=0;j<n;j++){
imag[i][j]=sc.nextInt();
v1.add(imag[i][j]);
}
Collections.sort(v1);
//System.out.println(Arrays.toString(v1.toArray()));
HashSet<Integer> uniqueValues = new HashSet<>(v1);
//int occurrences = Collections.frequency(animals, "bat");
Iterator it=uniqueValues.iterator();
while(it.hasNext()){
int c=(Integer)it.next();
//System.out.println(c);
int occurrences = Collections.frequency(v1, c); // find occurence of elements within collection
v2.add(c);
v2.add(occurrences);
}
// uniqueValues.forEach(System.out::println);
// System.out.println(Arrays.toString(v1.toArray()));
System.out.println(v1.size()-v2.size());
}
}