错误票据 - 永不冷�龅娜松�
int xorValue = a[0] - a[i]异或 min to max
then split xorValue based on last 1 in its bit
then ...
pre-sort: http://blog.csdn.net/milkcu/article/details/9090515
Use map
某涉密单位下发了某种票据,并要在年终全部收回。
每张票据有唯一的ID号。全年所有票据的ID号是连续的,但ID的开始数码是随机选定的。
因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成了某个ID断号,另外一个ID重号。
你的任务是通过编程,找出断号的ID和重号的ID。
假设断号不可能发生在最大和最小号。
要求程序首先输入一个整数N(N<100)表示后面数据行数。
接着读入N行数据。
每行数据长度不等,是用空格分开的若干个(不大于100个)正整数(不大于100000)
每个整数代表一个ID号。
要求程序输出1行,含两个整数m n,用空格分隔。
其中,m表示断号ID,n表示重号ID
例如:
用户输入:
2
5 6 8 11 9
10 12 9
则程序输出:
7 9
可以用位运算做int xorValue = a[0] - a[i]异或 min to max
then split xorValue based on last 1 in its bit
then ...
pre-sort: http://blog.csdn.net/milkcu/article/details/9090515
Use map
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int[] t = new int[n*100000];
int start = Integer.MAX_VALUE;
int end = Integer.MIN_VALUE;
cin.nextLine(); // 吸收一个换行符号
for(int i=0;i<n;i++){
String temp = cin.nextLine();
String[] m = temp.split(" ");
for(int j=0;j<m.length;j++){
int index = Integer.parseInt(m[j]) ;
if(index < start)
start = index;
if(index > end)
end = index;
t[index] ++;
}
}
int[] res = new int[2];
for(int i=start+1;i<end;i++){
if(t[i] == 0)
res[0] = i;
if(t[i] == 2)
res[1] = i;
}
System.out.println(res[0] + " " + res[1] );
}
Read full article from 错误票据 - 永不冷�龅娜松�