Step1

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) 
			arr[i] = sc.nextInt();
		int m = sc.nextInt();
		int i = 0;
		while(i < m) {
			int tmp = sc.nextInt();
			search(arr, tmp);
		}
	}
	public static void search(int[] arr,int x) {
		int left = 0;
		int right = arr.length - 1;
		while(left <= right) {
			int center = (left + right) / 2;
			if(arr[center] < x )
				left = center + 1;
			else if(arr[center] > x)
				right = center -1;	
			else {
				System.out.println(center + 1);
				return;
			}
		}
		System.out.println("No Found!");
	}
}

/***************************************************
User name: 自在飞花
Result: Memory Limit Exceeded
Take time: 0ms
Take Memory: 8192KB
Submit time: 2018-08-03 20:48:27
****************************************************/

你可能感兴趣的:(模拟题)