forked from python4geeks/Hactoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DifferenceOfTwoArray.java
99 lines (64 loc) · 1.4 KB
/
DifferenceOfTwoArray.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.Scanner;
public class DifferenceOfTwoArray {
private static void Display(int arr[])
{
for (int val : arr) {
System.out.println(val);
}
}
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int tcOne = scn.nextInt();
int arrOne[] = new int[tcOne];
for (int i = 0; i < arrOne.length; i++) {
arrOne[i] = scn.nextInt();
}
int tcTwo = scn.nextInt();
int arrTwo[] = new int[tcTwo];
for (int i = 0; i < arrTwo.length; i++) {
arrTwo[i] = scn.nextInt();
}
int arrDiff[] = new int[tcTwo ];
int i = arrOne.length - 1;
int j = arrTwo.length - 1;
int k = arrDiff.length - 1;
int c = 0;
while(k >= 0)
{
int d = c;
int a1v = i >= 0? arrOne[i]:0;
if( arrTwo[j]+c>=a1v)
{
d = arrTwo[j]+c - a1v;
c = 0;
}
else
{
d = arrTwo[j]+ c + 10 - a1v;
c= -1;
}
arrDiff[k] = d;
i--;
j--;
k--;
}
int idx = 0;
while(idx < arrDiff.length)
{
if(arrDiff[idx] == 0)
{
idx++;
}
else
{
break;
}
}
while(idx < arrDiff.length)
{
System.out.println(arrDiff[idx]);
idx++;
}
// Display(arrDiff);
}
}