본문 바로가기
백준 문제 풀이 & C++ 공부

백준 1269 C++

by daisy0461 2025. 2. 9.

https://www.acmicpc.net/problem/1269

sort 이후 Index 옮기면서 풀면 간단한 문제다.

 

#include <bits/stdc++.h>

using namespace std;

int a, b;	
vector<int> va, vb;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> a >> b;
	int temp;
	for (int i = 0; i < a; i++) {
		cin >> temp;
		va.push_back(temp);
	}
	for (int i = 0; i < b; i++) {
		cin >> temp;
		vb.push_back(temp);
	}

	sort(va.begin(), va.end());
	sort(vb.begin(), vb.end());

	int Same = 0;
	int aIndex = 0, bIndex = 0;
	while (aIndex != va.size() && bIndex != vb.size()) {
		if (va[aIndex] == vb[bIndex]) {
			Same += 1;
			aIndex += 1; bIndex += 1;
		}
		else if (va[aIndex] > vb[bIndex]) {		//a가 더 크다.
			bIndex += 1;
		}
		else if (va[aIndex] < vb[bIndex]) {
			aIndex += 1;
		}
	 }

	cout << va.size() + vb.size() - Same * 2;
}

'백준 문제 풀이 & C++ 공부' 카테고리의 다른 글

백준 1072 C++  (0) 2025.02.10
백준 1269 C++  (0) 2025.02.10
백준 7795 C++  (0) 2025.02.09
백준 6236 C++  (0) 2025.02.09
백준 2792 C++  (0) 2025.02.07