Skip to content

Instantly share code, notes, and snippets.

@AbsolutelySaurabh
Created December 10, 2019 05:45
Show Gist options
  • Select an option

  • Save AbsolutelySaurabh/7d87d5eef8985dc02880373dc9a3fad5 to your computer and use it in GitHub Desktop.

Select an option

Save AbsolutelySaurabh/7d87d5eef8985dc02880373dc9a3fad5 to your computer and use it in GitHub Desktop.

Revisions

  1. AbsolutelySaurabh created this gist Dec 10, 2019.
    59 changes: 59 additions & 0 deletions MaxAvgStudents
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    package practice;

    import java.util.LinkedHashMap;
    import java.util.Map;
    import java.util.Scanner;

    public class Solution2 {


    private static Map<String, Double> studentsMap;
    private static double max = -1;
    private static double getAvg(int a, int b, int c){
    double avg = (a+b+c)/3;
    if(avg > max){
    max = avg;
    }
    return avg;
    }

    private static String maxAvg(){
    String output = "";

    for(Map.Entry<String, Double> student : studentsMap.entrySet()){
    if(student.getValue() == max){
    if(output.length() == 0){
    output+=student.getKey();
    }else
    output = output + " " + student.getKey();
    }
    }
    output = output + " " + max;
    return output;
    }

    public static void main(String[] args) {

    Scanner s = new Scanner(System.in);
    int test = s.nextInt();
    s.nextLine();
    while(test > 0){

    studentsMap = new LinkedHashMap<String, Double>();
    int students = 3;
    while(students > 0){
    String name = s.nextLine();
    int marks1 = s.nextInt();
    int marks2 = s.nextInt();
    int marks3 = s.nextInt();
    s.nextLine();
    studentsMap.put(name, getAvg(marks1, marks2, marks3));
    students--;
    }
    System.out.println(maxAvg());
    test--;
    }
    s.close();
    }

    }