public class Student {
private String name;
private double[] grades;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double[] getGrades() {
return grades;
}
public void setGrades(double[] grades) {
this.grades = grades;
}
public Student(String name, double[] grades) {
this.name = name;
this.grades = grades;
}
}
import java.util.*;
public class AverageGrades {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int linesCount = Integer.parseInt(scanner.nextLine());
ArrayList<Student> students = new ArrayList<>();
for (int i = 0; i < linesCount; i++) {
String data = scanner.nextLine();
System.out.println(data);
String name = data.split(" ")[0];
data = data.replace(name + " ", "");
double[] grades = Arrays.stream(data.split(" ")).mapToDouble(Double::parseDouble).toArray();
Student currentStudent = new Student(name,grades);
students.add(currentStudent);
}
Comparator<Student> nameComparator = (s1, s2) -> (s1.getName() + s1.getGrades().toString()).compareTo((s2.getName() + s2.getGrades().toString()));
students.sort(nameComparator);
for(Student student : students) {
if(Arrays.stream(student.getGrades()).average().getAsDouble() >= 5.00) {
String s = String.format("%.2f", Arrays.stream(student.getGrades()).average().getAsDouble()).replace(",", ".") ;
System.
out.
printf("%s -> %s\n",student.
getName(), s
);// Arrays.stream(s.getGrades()).average().getAsDouble()); }
}
}
}
cHVibGljIGNsYXNzIFN0dWRlbnQgewogICAgcHJpdmF0ZSBTdHJpbmcgbmFtZTsKICAgIHByaXZhdGUgZG91YmxlW10gZ3JhZGVzOwoKICAgIHB1YmxpYyBTdHJpbmcgZ2V0TmFtZSgpIHsKICAgICAgICByZXR1cm4gbmFtZTsKICAgIH0KCiAgICBwdWJsaWMgdm9pZCBzZXROYW1lKFN0cmluZyBuYW1lKSB7CiAgICAgICAgdGhpcy5uYW1lID0gbmFtZTsKICAgIH0KCiAgICBwdWJsaWMgZG91YmxlW10gZ2V0R3JhZGVzKCkgewogICAgICAgIHJldHVybiBncmFkZXM7CiAgICB9CgogICAgcHVibGljIHZvaWQgc2V0R3JhZGVzKGRvdWJsZVtdIGdyYWRlcykgewogICAgICAgIHRoaXMuZ3JhZGVzID0gZ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