[BOJ] 11728 배열 합치기

Time Lapse :None

11728.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAXSIZE 1000000
int arr[MAXSIZE];
int arr2[MAXSIZE];

int N, M;

int main(void)
{
int _N = 0, _M = 0;

cin >> N >> M;

for (int i = 0; i < N; i++)
{
cin >> arr[i];
}

for (int i = 0; i < M; i++)
{
cin >> arr2[i];
}

while (1)
{
if (N == _N && M == _M)
break;

if(N > _N && (M==_M|| arr[_N] < arr2[_M]))
cout << arr[_N++] << " ";
else
cout << arr2[_M++] << " ";
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/11728/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.