Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int countN = in.nextInt();
- int[] arrA = new int[countN];
- for(int i = 0; i < countN; i++) {
- arrA[i] = in.nextInt();
- }
- int countM = in.nextInt();
- int[] arrB= new int[countM];
- for(int i = 0; i < countM; i++) {
- arrB[i] = in.nextInt();
- }
- int[] arrItog = new int[countM];
- int min;
- int minIndex = 0;
- for(int i = 0; i < countM; i++) {
- min = 50001;
- for(int j = 0; j < countN; j++) {
- if (min >= Math.abs(arrA[j] - arrB[i])) {
- min = Math.abs(arrA[j] - arrB[i]);
- minIndex = j;
- }
- }
- arrItog[i] = arrA[minIndex];
- }
- for(int i = 0; i < countM; i++) {
- if(i == countM - 1) {
- System.out.print(arrItog[i]);
- } else {
- System.out.println(arrItog[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement