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 | 29 | 30 | 31 |
Tags
- 유니온 파인드
- 알고리즘
- 백준
- ue5
- Team Fortress 2
- 누적 합
- 시뮬레이션
- 그리디 알고리즘
- 투 포인터
- 다이나믹 프로그래밍
- 브루트포스
- 자료구조
- 재귀
- 문자열
- VR
- 백트래킹
- 스택
- 구현
- 우선순위 큐
- Unreal Engine 5
- DFS
- XR Interaction Toolkit
- 그래프
- 다익스트라
- BFS
- 정렬
- 수학
- c++
- 유니티
- 트리
Archives
- Today
- Total
1일1알
백준 4158번 CD 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;
while (true) {
cin >> n >> m;
if (n == 0 && m == 0) break;
vector<int> v1(n);
vector<int> v2(m);
for (int i = 0; i < n; i++) {
cin >> v1[i];
}
for (int i = 0; i < m; i++) {
cin >> v2[i];
}
int p1 = 0;
int p2 = 0;
int cnt = 0;
while (true) {
if (p1 == n - 1 && p2 == m - 1) {
if (v1[p1] == v2[p2]) cnt++;
break;
}
if (p1 == n - 1) {
if (v1[p1] == v2[p2]) cnt++;
p2++;
continue;
}
if (p2 == m - 1) {
if (v1[p1] == v2[p2]) cnt++;
p1++;
continue;
}
if (v1[p1] == v2[p2]) {
cnt++;
p1++;
p2++;
}
else if (v1[p1] > v2[p2]) p2++;
else p1++;
}
cout << cnt << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 14226번 이모티콘 C++ (0) | 2022.03.13 |
---|---|
백준 2631번 줄세우기 C++ (0) | 2022.03.12 |
백준 14246번 k보다 큰 구간 C++ (0) | 2022.03.10 |
백준 2118번 두 개의 탑 C++ (0) | 2022.03.09 |
백준 4929번 수열 걷기 C++ (0) | 2022.03.08 |