-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMIXCOLOR.java
More file actions
59 lines (52 loc) · 1.25 KB
/
MIXCOLOR.java
File metadata and controls
59 lines (52 loc) · 1.25 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
import java.util.Scanner;
public class MIXCOLOR
{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
for(int t1=0;t1<t;t1++)
{
int n=scan.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++)
a[i]=scan.nextInt();
sort(a, 0, n);
int count=0,temp;
temp=a[0];
for(int i=1;i<n;i++)
{
if(temp==a[i])
count++;
temp=a[i];
}
System.out.println(count);
}
}
/* Merge Sort function */
public static void sort(int[] a, int low, int high)
{
int N = high - low;
if (N <= 1)
return;
int mid = low + N/2;
// recursively sort
sort(a, low, mid);
sort(a, mid, high);
// merge two sorted subarrays
int[] temp = new int[N];
int i = low, j = mid;
for (int k = 0; k < N; k++)
{
if (i == mid)
temp[k] = a[j++];
else if (j == high)
temp[k] = a[i++];
else if (a[j]<a[i])
temp[k] = a[j++];
else
temp[k] = a[i++];
}
for (int k = 0; k < N; k++)
a[low + k] = temp[k];
}
}