Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exams;
- import java.util.Map.Entry;
- import java.util.Scanner;
- import java.util.TreeMap;
- import java.util.TreeSet;
- public class ExamScore {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- scn.nextLine();
- scn.nextLine();
- scn.nextLine();
- TreeMap<Integer, TreeMap<TreeSet<String>, Double>> scores = new TreeMap<>();
- while (true) {
- String[] line = scn.nextLine().split("[| ]+");
- if (line.length < 5) {
- break;
- }
- String name =line[1] + " " + line[2];
- int score = Integer.parseInt(line[3]);
- double grade = Double.parseDouble(line[4]);
- if (scores.containsKey(score)) {
- TreeMap<TreeSet<String>, Double> student = scores.get(score);
- for (Entry<TreeSet<String>, Double> string : student.entrySet()) {
- TreeSet<String> studentName = string.getKey();
- studentName.add(name);
- double gradeAVG = string.getValue();
- gradeAVG = (grade + gradeAVG) / 2;
- student.put(studentName, gradeAVG);
- }
- scores.put(score, student);
- }
- else {
- TreeMap<TreeSet<String>, Double> student = new TreeMap<>();
- TreeSet<String> studentName = new TreeSet<>();
- studentName.add(name);
- student.put(studentName, grade);
- scores.put(score, student);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement