|
| 1 | +package AppleAndOrange; |
| 2 | + |
| 3 | +import java.io.*; |
| 4 | +import java.math.*; |
| 5 | +import java.security.*; |
| 6 | +import java.text.*; |
| 7 | +import java.util.*; |
| 8 | +import java.util.concurrent.*; |
| 9 | +import java.util.regex.*; |
| 10 | + |
| 11 | +class Result { |
| 12 | + |
| 13 | + /* |
| 14 | + * Complete the 'countApplesAndOranges' function below. |
| 15 | + * |
| 16 | + * The function accepts following parameters: |
| 17 | + * 1. INTEGER s |
| 18 | + * 2. INTEGER t |
| 19 | + * 3. INTEGER a |
| 20 | + * 4. INTEGER b |
| 21 | + * 5. INTEGER_ARRAY apples |
| 22 | + * 6. INTEGER_ARRAY oranges |
| 23 | + */ |
| 24 | + |
| 25 | + public static void countApplesAndOranges(int s, int t, int a, int b, List<Integer> apples, List<Integer> oranges) { |
| 26 | + // Write your code here |
| 27 | + int appleCount = 0; |
| 28 | + int orangeCount = 0; |
| 29 | + for (int i = 0; i < apples.size(); i++) { |
| 30 | + if (a + apples.get(i) >= s && a + apples.get(i) <= t) appleCount++; |
| 31 | + } |
| 32 | + |
| 33 | + System.out.println(appleCount); |
| 34 | + |
| 35 | + for (int j = 0; j < oranges.size(); j++) { |
| 36 | + if (b + oranges.get(j) >= s && b + oranges.get(j) <= t) orangeCount++; |
| 37 | + } |
| 38 | + |
| 39 | + System.out.println(orangeCount); |
| 40 | + } |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +public class Solution { |
| 45 | + public static void main(String[] args) throws IOException { |
| 46 | + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); |
| 47 | + |
| 48 | + String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); |
| 49 | + |
| 50 | + int s = Integer.parseInt(firstMultipleInput[0]); |
| 51 | + |
| 52 | + int t = Integer.parseInt(firstMultipleInput[1]); |
| 53 | + |
| 54 | + String[] secondMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); |
| 55 | + |
| 56 | + int a = Integer.parseInt(secondMultipleInput[0]); |
| 57 | + |
| 58 | + int b = Integer.parseInt(secondMultipleInput[1]); |
| 59 | + |
| 60 | + String[] thirdMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); |
| 61 | + |
| 62 | + int m = Integer.parseInt(thirdMultipleInput[0]); |
| 63 | + |
| 64 | + int n = Integer.parseInt(thirdMultipleInput[1]); |
| 65 | + |
| 66 | + String[] applesTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); |
| 67 | + |
| 68 | + List<Integer> apples = new ArrayList<>(); |
| 69 | + |
| 70 | + for (int i = 0; i < m; i++) { |
| 71 | + int applesItem = Integer.parseInt(applesTemp[i]); |
| 72 | + apples.add(applesItem); |
| 73 | + } |
| 74 | + |
| 75 | + String[] orangesTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); |
| 76 | + |
| 77 | + List<Integer> oranges = new ArrayList<>(); |
| 78 | + |
| 79 | + for (int i = 0; i < n; i++) { |
| 80 | + int orangesItem = Integer.parseInt(orangesTemp[i]); |
| 81 | + oranges.add(orangesItem); |
| 82 | + } |
| 83 | + |
| 84 | + Result.countApplesAndOranges(s, t, a, b, apples, oranges); |
| 85 | + |
| 86 | + bufferedReader.close(); |
| 87 | + } |
| 88 | +} |
0 commit comments