-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdifference_in_array_elements.java
73 lines (61 loc) · 1.33 KB
/
difference_in_array_elements.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
import java.util.*;
public class Program
{
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
int n1=scn.nextInt();
int [] a1=new int [n1];
for(int i=0;i<a1.length;i++)
{
a1[i]=scn.nextInt();
}
int n2=scn.nextInt();
int [] a2=new int[n2];
for(int i=0;i<a2.length;i++)
{
a2[i]=scn.nextInt();
}
int[]diff=new int [n2];
int c=0;
int i=a1.length-1;
int j=a2.length-1;
int k=diff.length-1;
while(k>=0)
{
int d=0;
int a1v=i>=0?a1[i]:0;
if(a2[j]+c>=a1v)
{
d=a2[j]+c-a1v;
c=0;
}
else
{
d=a2[j]+c+10-a1v;
c=-1;
}
diff[k]=d;
i--;
j--;
k--;
}
int idx=0;
while(idx<diff.length)
{
if (diff[idx]==0)
{
idx++;
}
else
{
break;
}
}
while(idx<diff.length)
{
System.out.println(diff[idx]);
idx++;
}
}
}