-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText4.java
More file actions
46 lines (37 loc) · 829 Bytes
/
Text4.java
File metadata and controls
46 lines (37 loc) · 829 Bytes
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
package Hang_OJ;
import java.util.*;
//
//设定输入n个价格
//输入n个价格
//输出第三个最便宜的价格
//不存在的话返回-1
//
public class Text4 {
public static void main(String []args){
Scanner input = new Scanner(System.in);
int num = input.nextInt();
List<Integer> list = new ArrayList<Integer>();
while(num>0){
list.add(Integer.parseInt(input.next()));
num--;
}
Collections.sort(list);
for(int i=0;i<list.size();i++)
{
for (int j=i+1;j<list.size();j++){
if(list.get(i)==list.get(j)){
list.remove(j);
j--;
}
}
}
if(list.size()<3){
System.out.println("-1");
}else{
System.out.println(list.get(2));
}
// for(int i=0;i<list.size();i++){ //测试
// System.out.print (list.get(i)+" ");
// }
}
}