-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifferenceofarray.java
More file actions
58 lines (49 loc) · 974 Bytes
/
Copy pathdifferenceofarray.java
File metadata and controls
58 lines (49 loc) · 974 Bytes
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
import java.util.*;
public class differenceofarray {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n1 = sc.nextInt();
int a1[] = new int[n1];
for(int i = 0; i<a1.length;i++){
a1[i]=sc.nextInt();
}
int n2= sc.nextInt();
int a2[]= new int[n2];
for(int i = 0 ; i<a2.length;i++){
a2[i] =sc.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;
if(a2[j]+c>=a1[i]){
d=a2[j]+c-a1[i];
c=0;
}
else{
d=a2[j]+c+10-a1[i];
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++;
}
}
}