• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Apple and Orange

plekekekeke Sep 23rd, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import java.io.*;
2. import java.math.*;
3. import java.security.*;
4. import java.text.*;
5. import java.util.*;
6. import java.util.concurrent.*;
7. import java.util.regex.*;
8.
9. public class Solution {
10.
11.     // Complete the countApplesAndOranges function below.
12.     static void countApplesAndOranges(int s, int t, int a, int b, int[] apples, int[] oranges) {
13.         int apple_top_house = 0;
14.         int orange_top_house = 0;
15.
16.         // Transform m to a
17.         for (int i = 0; i < apples.length; i++) {
18.             apples[i] += a;
19.             if (apples[i] >= s && apples[i] <= t) {
20.                 apple_top_house++;
21.             }
22.         }
23.
24.         for (int i = 0; i < oranges.length; i++) {
25.             oranges[i] += b;
26.             if (oranges[i] >= s && oranges[i] <= t) {
27.                 orange_top_house++;
28.             }
29.         }
30.         System.out.println(apple_top_house);
31.         System.out.println(orange_top_house);
32.         return;
33.     }
34.
35.     private static final Scanner scanner = new Scanner(System.in);
36.
37.     public static void main(String[] args) {
38.         String[] st = scanner.nextLine().split(" ");
39.
40.         int s = Integer.parseInt(st[0]);
41.
42.         int t = Integer.parseInt(st[1]);
43.
44.         String[] ab = scanner.nextLine().split(" ");
45.
46.         int a = Integer.parseInt(ab[0]);
47.
48.         int b = Integer.parseInt(ab[1]);
49.
50.         String[] mn = scanner.nextLine().split(" ");
51.
52.         int m = Integer.parseInt(mn[0]);
53.
54.         int n = Integer.parseInt(mn[1]);
55.
56.         int[] apples = new int[m];
57.
58.         String[] applesItems = scanner.nextLine().split(" ");
59.         scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
60.
61.         for (int i = 0; i < m; i++) {
62.             int applesItem = Integer.parseInt(applesItems[i]);
63.             apples[i] = applesItem;
64.         }
65.
66.         int[] oranges = new int[n];
67.
68.         String[] orangesItems = scanner.nextLine().split(" ");
69.         scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
70.
71.         for (int i = 0; i < n; i++) {
72.             int orangesItem = Integer.parseInt(orangesItems[i]);
73.             oranges[i] = orangesItem;
74.         }
75.
76.         countApplesAndOranges(s, t, a, b, apples, oranges);
77.
78.         scanner.close();
79.     }
80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top