Collection (Autumn 2017 Jingdong recruit Zhenti)

Title Description
								

Give you two sets, required {A} + {B}.

Note: with a collection will not have two of the same elements.

Entry

A plurality of sets (no more than 5 groups) of data.

Each set of input data is divided into three lines, the first line has two numbers n, m ($ 0 <n, m \ leq10000 $), respectively, the number of elements of the set A and set B. The next two lines indicate the set A and set B. Each element is an integer int without departing from the scope, there is a space between each of the spaced elements.

Export

A row of data for each set of output data representing a set of the merged output required from small to large, there is a space between each of the spaced elements.

Sample input

1 2
1
2 3
1 2
1
1 2

Sample Output

1 2 3
1 2

My thoughts: First, a definition of the size m + n array of integers, and then input into the first array of a first, a second input of each array, this number if there are prior to the detection array. For example, the first array is 1, 2, and then enter a 3, this time you can not get a hold of, so nothing is executed, if it is a 4, then there is no array 4, put 4 added. ~ ~ Finally arranged it.

Is worth to say about this format: I tried a few more little space a few all right, it requires a space between the two elements, but I tried it, between the two elements 2, 3 , 4 spaces, the final surface there is no space will do. At this time I do not understand ~~

code show as below:

import java.util. *;

import java.util.Scanner;

public class Main {

public static boolean get(int[] array,int m,int n) {

        int num = 0;

        for(int i=0;i<m;i++)

if(array[i]==n)

a ++;

if(num==0)

        return false;

        else

        return true;

}

public static void main(String[] args){

        Scanner input = new Scanner(System.in);

         while(input.hasNext()){

        int n=input.nextInt();

        int m=input.nextInt();

int num=n;

        int [] array_n=new int [n+m];

        for(int i=0;i<n;i++)

        {

        array_n[i]=input.nextInt();

        }

        for(int i=0;i<m;i++)

{

    int temp=input.nextInt(); 

if(!get(array_n,num,temp))

{

    array_n[num]=temp;

    num++;

        }

}

Arrays.sort(array_n, 0, num);

//System.out.print(num);

for(int i=0;i<num;i++)

        {

            System.out.print(array_n[i]+" ");

            }

        }

    }

}

Guess you like

Origin blog.csdn.net/mad_sword/article/details/79671305