解题思路:
1. 重号:使用Map存储ID,判断重复key,即可得到重复ID
2. 断号:先得到所有ID序列的最小值和最大值,循环判断不存在于Map中的ID,即可得到断号
注意事项:
参考代码:import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class C1458 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int m = 0, n = 0;
int N = sc.nextInt();
sc.nextLine();
Map map = new HashMap();
int min = Integer.MAX_VALUE, max = 0, num;
for(int i = 0; i
String[] strs = sc.nextLine().split("[ ]+");
for(String str : strs){
num = Integer.valueOf(str);
if(map.containsKey(num)) //重号ID
n = num;
else
map.put(num, num);
if(num
min = num;
if(num > max)
max = num;
}
}
for(int i = min; i <= max; i++){
if(!map.containsKey(i)){//断号
m = i;
break;
}
}
System.out.printf("%d %d", m, n);
}
sc.close();
}
}