-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI015.java
More file actions
184 lines (176 loc) · 7.32 KB
/
I015.java
File metadata and controls
184 lines (176 loc) · 7.32 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package levelB;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class I015 {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str[]=br.readLine().split(" ");
int N=Integer.parseInt(str[0]);//多少学生
int L=Integer.parseInt(str[1]);//最低分数线
int H=Integer.parseInt(str[2]);//优先录取线
int[] id=new int[N];//存放学号
int[] de=new int[N];//德分
int[] cai=new int[N];//才分
int[] sum=new int[N];//分数和
int flag[]=new int[N];//标记数组
/*这个标记数组,0代表淘汰,1代表才德全尽,2代表德胜才,
3代表尚有德胜才,4代表除了0123的剩下的*/
int temp1,temp2;//temp1代表录入的德分,temp2代表才分
for(int i=0;i<N;i++){
str=br.readLine().split(" ");
id[i]=Integer.parseInt(str[0]);
temp1=Integer.parseInt(str[1]);
temp2=Integer.parseInt(str[2]);
if(temp1>=L&&temp2>=L){
if(temp1>=H&&temp2>=H){//德才分均大于H
de[i]=temp1;
cai[i]=temp2;
flag[i]=1; //置为1
sum[i]=temp1+temp2;
}else if(temp1>=H&&temp2<H){ //德过线才不过
de[i]=temp1;
cai[i]=temp2;
flag[i]=2;//置为2
sum[i]=temp1+temp2;
}else if(temp1<H&&temp2<H&&temp1>=temp2){ //尚有德胜才
de[i]=temp1;
cai[i]=temp2;
flag[i]=3;
sum[i]=temp1+temp2;
}else { //其他
de[i]=temp1;
cai[i]=temp2;
flag[i]=4;
sum[i]=temp1+temp2;
}
}else{ //淘汰
de[i]=temp1;
cai[i]=temp2;
flag[i]=0;
}
}
int temp;//中间数,交换数组对应位置数的时候用到
for(int i=0;i<N;i++){
for(int j=i;j<N;j++){
if(flag[i]==1&&flag[j]==1){//德才全尽排序
if(sum[i]<sum[j]){//按和降序排序
temp=sum[i];sum[i]=sum[j];sum[j]=temp;
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(sum[i]==sum[j]){//和相同
if(de[i]<de[j]){//按德分降序排序
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(de[i]==de[j]){//德相同按序号升序排序
if(id[i]>id[j]){
temp=id[i];id[i]=id[j];id[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}
}
}
}
}
}
/*看懂了上边那个,下面三个也就懂了,分别是对剩下三类进行排序*/
for(int i=0;i<N;i++){
for(int j=i;j<N;j++){
if(flag[i]==2&&flag[j]==2){
if(sum[i]<sum[j]){
temp=sum[i];sum[i]=sum[j];sum[j]=temp;
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(sum[i]==sum[j]){
if(de[i]<de[j]){
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(de[i]==de[j]){
if(id[i]>id[j]){
temp=id[i];id[i]=id[j];id[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}
}
}
}
}
}
for(int i=0;i<N;i++){
for(int j=i;j<N;j++){
if(flag[i]==3&&flag[j]==3){
if(sum[i]<sum[j]){
temp=sum[i];sum[i]=sum[j];sum[j]=temp;
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(sum[i]==sum[j]){
if(de[i]<de[j]){
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(de[i]==de[j]){
if(id[i]>id[j]){
temp=id[i];id[i]=id[j];id[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}
}
}
}
}
}
for(int i=0;i<N;i++){
for(int j=i;j<N;j++){
if(flag[i]==4&&flag[j]==4){
if(sum[i]<sum[j]){
temp=sum[i];sum[i]=sum[j];sum[j]=temp;
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(sum[i]==sum[j]){
if(de[i]<de[j]){
temp=id[i];id[i]=id[j];id[j]=temp;
temp=de[i];de[i]=de[j];de[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}else if(de[i]==de[j]){
if(id[i]>id[j]){
temp=id[i];id[i]=id[j];id[j]=temp;
temp=cai[i];cai[i]=cai[j];cai[j]=temp;
}
}
}
}
}
}
//记录总共要输出的个数
int count=0;
for(int i=0;i<N;i++){
if(flag[i]!=0){
count++;
}
}
System.out.println(count);
//输出最后结果
for(int i=0;i<N;i++){
if(flag[i]==1){
System.out.println(id[i]+" "+de[i]+" "+cai[i]);
}
}
for(int i=0;i<N;i++){
if(flag[i]==2){
System.out.println(id[i]+" "+de[i]+" "+cai[i]);
}
}
for(int i=0;i<N;i++){
if(flag[i]==3){
System.out.println(id[i]+" "+de[i]+" "+cai[i]);
}
}
for(int i=0;i<N;i++){
if(flag[i]==4){
System.out.println(id[i]+" "+de[i]+" "+cai[i]);
}
}
}
}