hades

[Baekjoon] 1764๋ฒˆ: ๋“ฃ๋ณด์žก ๋ณธ๋ฌธ

๐Ÿ‘Š PS/Algorithm

[Baekjoon] 1764๋ฒˆ: ๋“ฃ๋ณด์žก

hades1 2024. 7. 9. 20:25

๐Ÿฅ… ๋ฌธ์ œ

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

 

๐Ÿ” ์„ค๊ณ„

๋“ฃ์ง€๋„ ๋ชปํ•˜๊ณ , ๋ณด์ง€๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„์„ ์ฐพ์•„์•ผ ํ•œ๋‹ค. ๋“ฃ์ง€๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์„ ์šฐ์„  ์ €์žฅํ•˜๊ณ , ๋ณด์ง€๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์ด ์ €์žฅํ•œ ์‚ฌ๋žŒ ์ค‘์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

 

๋ฌธ์ž์—ด์„ ํ‚ค๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ๋งต์„ ์ด์šฉํ•˜์—ฌ ๋“ฃ์ง€๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์„ ๋จผ์ € ์ €์žฅํ•˜๊ณ , ๋ณด์ง€๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์„ ๋งต์—์„œ findํ•˜์—ฌ ์žˆ๋‹ค๋ฉด ๊ฒฐ๊ณผ ๋ฒกํ„ฐ์— ์ €์žฅํ•œ๋‹ค. ์ €์žฅ๋œ ์‚ฌ๋žŒ์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ ํ›„ ์ถœ๋ ฅํ•œ๋‹ค.

 

๐Ÿ‘Š ํ’€์ด

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;	
int n, m;
string name;
map<string, int> mm;
vector<string> result;

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i=0; i<n; i++){
		cin >> name;
		mm.insert({name, 1});
	}
	for (int i=0; i<m; i++){
		cin >> name;
		if (mm.find(name) != mm.end()){
			result.push_back(name);		
		}
	}
	sort(result.begin(), result.end());
	cout << result.size() << "\n";
	for (int i=0; i<result.size(); i++){
		cout << result[i] << "\n";
	}
	return 0;
}

 

๐Ÿ“ ๋ฉ”๋ชจ

๋ฌธ์ž์—ด์„ ๊ฐ€์ง€๊ณ  ์ ‘๊ทผํ•˜๋ ค๊ณ  ํ•  ๋•Œ, ๋งต์ด ์œ ์šฉํ•˜๊ฒŒ ์“ฐ์ธ๋‹ค.