close

import java.util.Scanner;
public class UVa10611 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int fin = input.nextInt();
        int[] fh = new int[fin];
        int fn = 1, temp = 0;
        fh[0] = input.nextInt();
        for (int i = 1; i < fin; i++) {
            temp = input.nextInt();
            if (temp != fh[fn - 1])
                fh[fn++] = temp;
        }
        int bin = input.nextInt();
        for (int i = 0; i < bin; i++) {
            int bh = input.nextInt();
            int h = fn - 1;
            int l = 0;
            int m = (fn - 1) / 2;
            while (l < h) {
                if (bh > fh[m]) {
                    l = m + 1;
                    m = (h + l) / 2;
                }
                if (bh < fh[m]) {
                    h = m - 1;
                    m = (h + l) / 2;
                }
                if (bh == fh[m])
                    break;
            }
            if (fh[m] == bh) {
                if (m - 1 < 0)
                    System.out.print("X ");
                else
                    System.out.print(fh[m - 1] + " ");
                if (m + 1 > fn - 1)
                    System.out.println("X");
                else
                    System.out.println(fh[m + 1]);
            }
            if (fh[m] < bh) {
                System.out.print(fh[m] + " ");
                if (m + 1 > fn - 1)
                    System.out.println("X");
                else
                    System.out.println(fh[m + 1]);
            }
            if (fh[m] > bh) {
                if (m - 1 < 0)
                    System.out.print("X ");
                else
                    System.out.print(fh[m - 1] + " ");
                System.out.println(fh[m]);
            }
        }
    }
}

 

arrow
arrow
    文章標籤
    UVa JAVA code
    全站熱搜
    創作者介紹
    創作者 蒼雨 的頭像
    蒼雨

    日常雜物間

    蒼雨 發表在 痞客邦 留言(0) 人氣()