-
Notifications
You must be signed in to change notification settings - Fork 16
/
apple_and_orange.java
83 lines (56 loc) · 2.14 KB
/
apple_and_orange.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
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Solution {
/*
* Complete the countApplesAndOranges function below.
*/
static void countApplesAndOranges(int s, int t, int a, int b, int[] apples, int[] oranges) {
int length = Math.max(apples.length, oranges.length);
int count_a = 0;
int count_b = 0;
for(int i=0; i<length ; i++){
if(i < apples.length){
apples[i] = apples[i] + a;
if(apples[i] >=s && apples[i] <=t){
count_a++;
}
}
if(i < oranges.length){
oranges[i] = oranges[i] + b;
if(oranges[i] >=s && oranges[i] <=t){
count_b++;
}
}
}
System.out.println(count_a);
System.out.print(count_b);
}
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
String[] st = scan.nextLine().split(" ");
int s = Integer.parseInt(st[0].trim());
int t = Integer.parseInt(st[1].trim());
String[] ab = scan.nextLine().split(" ");
int a = Integer.parseInt(ab[0].trim());
int b = Integer.parseInt(ab[1].trim());
String[] mn = scan.nextLine().split(" ");
int m = Integer.parseInt(mn[0].trim());
int n = Integer.parseInt(mn[1].trim());
int[] apple = new int[m];
String[] appleItems = scan.nextLine().split(" ");
for (int appleItr = 0; appleItr < m; appleItr++) {
int appleItem = Integer.parseInt(appleItems[appleItr].trim());
apple[appleItr] = appleItem;
}
int[] orange = new int[n];
String[] orangeItems = scan.nextLine().split(" ");
for (int orangeItr = 0; orangeItr < n; orangeItr++) {
int orangeItem = Integer.parseInt(orangeItems[orangeItr].trim());
orange[orangeItr] = orangeItem;
}
countApplesAndOranges(s, t, a, b, apple, orange);
}
}