快手程序题java
第一题只过了3/4,就不放了,好心塞。
import java.util.HashMap;
import java.util.Scanner;public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Scanner sc = new Scanner(in.nextLine());
HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
int i = 0;
int min = 0,max = 0;
while(sc.hasNextInt()) {
max = sc.nextInt();
if(i == 0) {
min = max;
}
hm.put(max, i);
i++;
}
int x = in.nextInt();
if(x > max) {
System.out.println(hm.size());
}else if(x < min) {
System.out.println(0);
}else if(hm.containsKey(x)) {
System.out.println(hm.get(x));
}else {
while(true) {
x++;
if(hm.containsKey(x)) {
System.out.println(hm.get(x));
break;
}
}
}
}
}