-
Notifications
You must be signed in to change notification settings - Fork 110
/
Missing.java
59 lines (56 loc) · 1.37 KB
/
Missing.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
49
50
51
52
53
54
55
56
57
58
59
/*
*Input : 1 2 4 8 9 11 12 14
*Output : 3 5 6 7 10 13
*/
import java.util.*;
public class Missing {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int[] arr = new int[8];
int j;
int[] ans = new int[0];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
for (int i = 0; i < arr.length-1; i++) {
j=i;
int k = arr[j];
while(k+1!=arr[i+1])
{
ans = Arrays.copyOf(ans, ans.length+1);
ans[ans.length-1]=(k+1);
k++;
}
}
for (int i = 0; i < ans.length; i++) {
System.out.print(ans[i]+" ");
}
System.out.println();
}
}
/*
ANOTHER PROCESS
---------------------
import java.util.*;
public class test {
public static void main(String[]args)
{
Scanner sc= new Scanner(System.in);
int[] arr = new int[8];
for (int i = 0; i < arr.length; i++)
{
arr[i] = sc.nextInt();
}
int num;
for (int i = 0; i < arr.length-1; i++) {
num = arr[i];
while(num+1 != arr[i+1])
{
System.out.print(num+1+" ");
num++;
}
}
}
}
*/