Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package exams;
  2.  
  3. import java.util.Map.Entry;
  4. import java.util.Scanner;
  5. import java.util.TreeMap;
  6. import java.util.TreeSet;
  7.  
  8. public class ExamScore {
  9.  
  10.     public static void main(String[] args) {
  11.         Scanner scn = new Scanner(System.in);
  12.        
  13.         scn.nextLine();
  14.         scn.nextLine();
  15.         scn.nextLine();
  16.        
  17.         TreeMap<Integer, TreeMap<TreeSet<String>, Double>> scores = new TreeMap<>();
  18.        
  19.         while (true) {
  20.             String[] line = scn.nextLine().split("[| ]+");
  21.            
  22.             if (line.length < 5) {
  23.                 break;
  24.             }
  25.            
  26.             String name =line[1] + " " + line[2];
  27.             int score = Integer.parseInt(line[3]);
  28.             double grade = Double.parseDouble(line[4]);
  29.            
  30.             if (scores.containsKey(score)) {
  31.                 TreeMap<TreeSet<String>, Double> student = scores.get(score);
  32.                 for (Entry<TreeSet<String>, Double> string : student.entrySet()) {
  33.                    
  34.                     TreeSet<String> studentName = string.getKey();
  35.                     studentName.add(name);
  36.                    
  37.                     double gradeAVG = string.getValue();
  38.                     gradeAVG = (grade + gradeAVG) / 2;
  39.                     student.put(studentName, gradeAVG);
  40.                 }              
  41.                
  42.                 scores.put(score, student);
  43.             }
  44.             else {
  45.                 TreeMap<TreeSet<String>, Double> student = new TreeMap<>();
  46.                 TreeSet<String> studentName = new TreeSet<>();
  47.                 studentName.add(name);
  48.                 student.put(studentName, grade);
  49.                 scores.put(score, student);
  50.             }
  51.            
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement