-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollcall.java
81 lines (63 loc) · 1.53 KB
/
rollcall.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class student implements Comparable<student>
{
String name;
String last;
boolean rep;
public student(String name, String last)
{
this.name = name;
this.last = last;
}
public int compareTo(student s) {
return name.compareTo(s.name);
}
}
public class rollcall {
public static String last(String str)
{
return str.substring( str.indexOf(" ") + 1 );
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
ArrayList<student> students = new ArrayList<>();
while( scan.hasNextLine() )
{
students.add(new student(scan.next(), scan.next()));
scan.nextLine();
}
scan.close();
Collections.sort(students);
for(int i=0; i < students.size()-1; i++)
{
if(students.get(i).name.equals(students.get(i+1).name))
{
students.get(i).rep = true;
students.get(i+1).rep = true;
}
}
for(int i=0; i < students.size()-1; i++){
for(int j=0; j < students.size()-1-i; j++){
if(students.get(j).last.compareTo(students.get(j+1).last) > 0){
student temp = students.get(j);
students.set(j, students.get(j+1));
students.set(j+1, temp);
}
}
}
for(int i=0; i < students.size(); i++)
{
if(students.get(i).rep)
{
System.out.println( students.get(i).name + " " + students.get(i).last );
}
else
{
System.out.println( students.get(i).name );
}
}
}
}