From 5b20e0b5df739798f730dd21aa79a70794ba9cef Mon Sep 17 00:00:00 2001 From: RAHUL SENAPATI <72217211+rahul-7077@users.noreply.github.com> Date: Thu, 8 Oct 2020 20:43:13 +0530 Subject: [PATCH] Apple and Orange Prog. Sam's house has an apple tree and an orange tree that yield an abundance of fruit. We've to determine the number of apples and oranges that land on Sam's house. So, have a look on this prog... --- JavaHackerrank/A & O.java | 78 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 JavaHackerrank/A & O.java diff --git a/JavaHackerrank/A & O.java b/JavaHackerrank/A & O.java new file mode 100644 index 00000000..8ee57c29 --- /dev/null +++ b/JavaHackerrank/A & O.java @@ -0,0 +1,78 @@ +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 counta=0,counto=0; + int m = apples.length; + + for(int i=0;i=s && a+apples[i]<=t) + counta++; + } + int n = oranges.length; + for(int i=0;i=s) + counto++; + } + System.out.print("" +counta++); + System.out.print("\n" +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(); + } +}