From 0e2df4911197625e39f587cc7e71fc84e305e124 Mon Sep 17 00:00:00 2001 From: amit328 <51810663+amit328@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:14:09 +0530 Subject: [PATCH] apple and orange --- Algorithms/01. Warmup/apple and orange.java | 88 +++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Algorithms/01. Warmup/apple and orange.java diff --git a/Algorithms/01. Warmup/apple and orange.java b/Algorithms/01. Warmup/apple and orange.java new file mode 100644 index 0000000..64c48ec --- /dev/null +++ b/Algorithms/01. Warmup/apple and orange.java @@ -0,0 +1,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=s)&(apples[i]<=t)){ + counta+=1; + +} + + } + for(j=0;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(); + } +}