-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathapple and orange.java
More file actions
88 lines (62 loc) · 2.17 KB
/
apple and orange.java
File metadata and controls
88 lines (62 loc) · 2.17 KB
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
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
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 n=apples.length;
int m=oranges.length;
int i=0;
int j=0;
int counta=0;
int counto=0;
// int e[]=new int[a];
// int f[]=new int[b];
for(i=0;i<n;i++){
apples[i]=apples[i]+a;
if((apples[i]>=s)&(apples[i]<=t)){
counta+=1;
}
}
for(j=0;j<m;j++){
oranges[j]=oranges[j]+b;
if((oranges[j]>=s)&(oranges[j]<=t)){
counto+=1;
}
}
System.out.println(counta);
System.out.println(counto);
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
String[] st = scanner.nextLine().split(" ");
int s = Integer.parseInt(st[0]);
int t = Integer.parseInt(st[1]);
String[] ab = scanner.nextLine().split(" ");
int a = Integer.parseInt(ab[0]);
int b = Integer.parseInt(ab[1]);
String[] mn = scanner.nextLine().split(" ");
int m = Integer.parseInt(mn[0]);
int n = Integer.parseInt(mn[1]);
int[] apples = new int[m];
String[] applesItems = scanner.nextLine().split(" ");
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for (int i = 0; i < m; i++) {
int applesItem = Integer.parseInt(applesItems[i]);
apples[i] = applesItem;
}
int[] oranges = new int[n];
String[] orangesItems = scanner.nextLine().split(" ");
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for (int i = 0; i < n; i++) {
int orangesItem = Integer.parseInt(orangesItems[i]);
oranges[i] = orangesItem;
}
countApplesAndOranges(s, t, a, b, apples, oranges);
scanner.close();
}
}