-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpat1015.java
More file actions
153 lines (116 loc) · 3.25 KB
/
pat1015.java
File metadata and controls
153 lines (116 loc) · 3.25 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.util.*;
public class Main {
public static void main(String []args){
List<Student> students=new ArrayList<>();
List<Student>list=new ArrayList<>();
List<Student>result=new ArrayList<>();
int N,L,H;
Scanner sc=new Scanner(System.in);
N=sc.nextInt();
L=sc.nextInt();
H=sc.nextInt();
while (N>0){
Student student=new Student();
student.setNum(sc.next());
student.setD(sc.nextInt());
student.setC(sc.nextInt());
students.add(student);
N--;
}
for (int n=0;n<students.size();n++){
Student student=students.get(n);
if (student.getD()<L||student.getC()<L)
list.add(student);
}
students.removeAll(list);
list.clear();
for (Student stu:students)
{
if (stu.getD()>=H&&stu.getC()>=H) {
list.add(stu);
}
}
students.removeAll(list);
Collections.sort(list);
result.addAll(list);
list.clear();
for (Student s:students
) {
if (s.getD()>=H&&s.getC()<=H)
list.add(s);
}
Collections.sort(list);
students.removeAll(list);
result.addAll(list);
list.clear();
/*for (int i=0;i<list.size()-1;i++){
i++;
boolean sort=false;
for (int j=0;j<list.size()-i;j++){
if (list.get(j).getD()+list.get(j).getC()
>list.get(j+1).getC()+list.get(j+1).getD())
{
Student student=list.get(j);
list.set(j,list.get(j+1));
list.set(j+1,student);
sort=true;
System.out.println(j);
}
}
if (sort){
break;
}
}*/
for (Student s:students
) {
if (s.getC()<=H&&s.getD()<=H&&s.getD()>=s.getC())
list.add(s);
}
Collections.sort(list);
result.addAll(list);
students.removeAll(list);
list.clear();
list.addAll(students);
Collections.sort(list);
result.addAll(list);
System.out.println(result.size());
for (Student s:result
) {
System.out.print(s.getNum()+" "+s.getD());
System.out.println(" "+s.getC());
}
}
}
class Student implements Comparable<Student>{
private String num;
private int d;
private int c;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public int getD() {
return d;
}
public void setD(int d) {
this.d = d;
}
public int getC() {
return c;
}
public void setC(int c) {
this.c = c;
}
@Override
public int compareTo(Student o) {
if (o.getC()+o.getD()==d+c) {
if (o.getD()!=d)
return o.getD()-d;
else
return Integer.parseInt(num) - Integer.parseInt(o.getNum());
}
return (o.getC()+o.getD())-(d+c);
}
}