01-10 04:27
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_24 ๋‘ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ ๋ณธ๋ฌธ

Algorithm/Java

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_24 ๋‘ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ

miinsun 2022. 1. 4. 12:34

 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ์ด ๋œ ๋‘ ๋ฐฐ์—ด์ด ์ฃผ์–ด์ง€๋ฉด ๋‘ ๋ฐฐ์—ด์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ํ•ฉ์ณ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.

 

 

 

๐Ÿ”จ ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ - ์ฒซ ๋ฒˆ์งธ ์ค„์— ์ฒซ ๋ฒˆ์งธ ๋ฐฐ์—ด์˜ ํฌ๊ธฐ N(1<=N<=100)์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

๋‘ ๋ฒˆ์งธ ์ค„์— N๊ฐœ์˜ ๋ฐฐ์—ด ์›์†Œ๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

์„ธ ๋ฒˆ์งธ ์ค„์— ๋‘ ๋ฒˆ์งธ ๋ฐฐ์—ด์˜ ํฌ๊ธฐ M(1<=M<=100)์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

๋„ค ๋ฒˆ์งธ ์ค„์— M๊ฐœ์˜ ๋ฐฐ์—ด ์›์†Œ๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

๊ฐ ๋ฆฌ์ŠคํŠธ์˜ ์›์†Œ๋Š” intํ˜• ๋ณ€์ˆ˜์˜ ํฌ๊ธฐ๋ฅผ ๋„˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

3
1 3 5
5
2 3 6 7 9

์ถœ๋ ฅ - ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ๋ฐฐ์—ด์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

1 2 3 3 5 6 7 9

 

 

โ€‹

๐Ÿ’ป Solution.java

import java.util.*;

public class Main {
	public int[] solution(int n, int m, int[] arr1, int[] arr2) {
		int[] answer = new int[n + m];
		
		System.arraycopy(arr1, 0, answer, 0, n);  
        	System.arraycopy(arr2, 0, answer, n, m);  
		Arrays.sort(answer);
		return answer;
	}
	
	public static void main(String[] args){
		Main main  = new Main();
		Scanner sc =new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] arr1 = new int[n];

		for(int i = 0; i < n; i++) {
			arr1[i] = sc.nextInt();
		}
		
		int m = sc.nextInt();
		int[] arr2 = new int[m];
		for(int i = 0; i < m; i++) {
			arr2[i] = sc.nextInt();
		}

		for(int num : main.solution(n , m, arr1, arr2)) {
			System.out.print(num + " ");
		}
		
		System.out.println();
		
		sc.close();
		return ;
	}
}

 

 

 

Comments