Scanner sc = new Scanner(System.in);
int ppl = sc.nextInt(); //Number of students
int ps = sc.nextInt(); //Passing score
Map<Integer, Stud> map = new LinkedHashMap<>(); //Have a student ID number and Stud class
for(int i = 1; i <= ppl; i++) {
int a = sc.nextInt(); //Test score
int b = sc.nextInt(); //Number of absences
Stud s = new Stud(a, b); //Instantiation
map.put(i, s); //Fill the map with student ID numbers and instances
}
for(int key : map.keySet()) {
Stud c = map.get(key);
int d = c.score; //Scores for each student ID number
int e = c.absent; //Number of absences
int f = d - e * 5; //Calculate the final score
if(f <= 0) { //If the score becomes negative as a result of the calculation, set 0 as the lower limit.
f = 0;
}
if(f >= ps) {
System.out.println(key);
}
}
}
}
class Stud { //Student class
int score; //Score
int absent; //Number of absences
public Stud(int score, int absent) {
this.score = score;
this.absent = absent;
}
}
I first came up with an array method, but it seemed to be complicated, so I tried using Map. I wanted to retrieve them in the order they were packed, so I used LinkedHashMap.
Recommended Posts