P8598 [蓝桥杯 2013 省 AB] 错误票据
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
int N = sc.nextInt();
sc.nextLine();//吃掉整数后面的换行符
for (int i = 0; i < N; i++) {//输入所有的数
String line = sc.nextLine();
String[] split = line.split(" ");//用空格进行分割,得到若干字符串
for (int j = 0; j < split.length; j++) {//遍历所有的数
list.add(Integer.parseInt(split[j]));//解析为整数
}
}
// System.out.println(list.size());
Collections.sort(list);//顺序扫描
int a = 0, b = 0;//a是缺号,b是重号
for (int i = 1; i < list.size(); i++) {
if (list.get(i) - list.get(i - 1) == 2)//后面减前面等于2不就等于他断开了么
a = list.get(i) - 1;
if (list.get(i) - list.get(i - 1) == 0)//后面减前面等于0不就等于他重号了么
b = list.get(i);
}
System.out.println(a + " " + b);
}
}
这里if (list.get(i) - list.get(i - 1) == 0)和if (list.get(i) == list.get(i - 1) )有什么区别
为什么换成第二个就有一个测试点错误?