From 3538b21d0e7be63e6033151baab9ce1a9ffa367d Mon Sep 17 00:00:00 2001 From: Parvez Ahmed <114897117+Parvez7421@users.noreply.github.com> Date: Mon, 3 Oct 2022 13:37:54 +0530 Subject: [PATCH] Create Main.java --- Main.java | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Main.java diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..f496411 --- /dev/null +++ b/Main.java @@ -0,0 +1,65 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; + +class Item { + String name; + int price; + + public Item(String name, int price) { + this.name = name; + this.price = price; + } + + public String toString() { + return this.name + ": " + this.price; + } +} + +public class Main { + public static void main(String[] args) throws Exception { + FileInputStream fis=new FileInputStream("input.txt"); + Scanner sc=new Scanner(fis); + int number_of_employees = Integer.parseInt(sc.nextLine().split(": ")[1]); + sc.nextLine(); sc.nextLine(); sc.nextLine(); + + ArrayList goodies_items = new ArrayList(); + + while(sc.hasNextLine()) + { + String current[] = sc.nextLine().split(": "); + goodies_items.add(new Item(current[0], Integer.parseInt(current[1]))); + } + sc.close(); + + Collections.sort(goodies_items, new Comparator(){ + public int compare(Item a, Item b) { + return a.price - b.price; + } + }); + + int min_diff = goodies_items.get(goodies_items.size()-1).price; + int min_index = 0; + for(int i=0;i