Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 정렬
- 문자열
- 수학
- VR
- ue5
- 그리디 알고리즘
- 재귀
- XR Interaction Toolkit
- 다이나믹 프로그래밍
- 유니온 파인드
- Team Fortress 2
- 알고리즘
- 그래프
- 백트래킹
- 누적 합
- 우선순위 큐
- 시뮬레이션
- 트리
- 백준
- 유니티
- Unreal Engine 5
- DFS
- BFS
- c++
- 투 포인터
- 자료구조
- 스택
- 다익스트라
- 구현
- 브루트포스
Archives
- Today
- Total
1일1알
백준 11728번 배열 합치기 C++ 본문
이미 정렬되어있는 배열 두개를 합치는 것이기 때문에 앞쪽부터 비교하면서 작은 순서대로 새로운 배열에 넣어주었다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
int p1 = 0;
int p2 = 0;
vector<int> v1(n);
vector<int> v2(m);
vector<int> ans;
for (int i = 0; i < n; i++) {
cin >> v1[i];
}
for (int i = 0; i < m; i++) {
cin >> v2[i];
}
while (p1 < n || p2 < m) {
if (p1 >= n) ans.push_back(v2[p2++]);
else if (p2 >= m) ans.push_back(v1[p1++]);
else if (v1[p1] >= v2[p2]) ans.push_back(v2[p2++]);
else ans.push_back(v1[p1++]);
}
for (auto a : ans) {
cout << a << " ";
}
};
'알고리즘' 카테고리의 다른 글
백준 24954번 물약 구매 C++ (0) | 2022.05.16 |
---|---|
백준 17359번 전구 길만 걷자 C++ (0) | 2022.05.14 |
백준 10819번 차이를 최대로 C++ (0) | 2022.05.12 |
백준 2417번 정수 제곱근 C++ (0) | 2022.05.11 |
백준 10867번 중복 빼고 정렬하기 C++ (0) | 2022.05.10 |