Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(1764) 듣보잡 본문

백준 (C++)/Solve

(1764) 듣보잡

dh-winternagi 2026. 4. 14. 12:02

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

단계별로 풀어보기

14단계(집합과 맵) 6번째

 

 

 

어렵게 쓰여있지만 해석하면 A와 B의 교집합을 구하면 되는 문제

입력 데이터를 보존할 필요가 없으니 A를 먼저 저장한 뒤 B의 각 원소가 A에 속하는지 확인만 하면 된다.

 

 

 

#include <iostream>
#include <set>
using namespace std;

int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  int n, m;
  set<string> s, ans;
  
  cin >> n >> m;
  
  while(n--){
    string name;
    
    cin >> name;
    
    s.insert(name);
  }
  
  while(m--){
    string name;
    
    cin >> name;
    
    if(s.count(name))  ans.insert(name);
  }
  
  cout << ans.size() << "\n";
  for(string elem:ans)  cout << elem << "\n";
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(11478) 서로 다른 부분 문자열의 개수  (0) 2026.04.14
(1269) 대칭 차집합  (0) 2026.04.14
(10816) 숫자 카드 2  (0) 2026.04.14
(1620) 나는야 포켓몬 마스터 이다솜  (0) 2026.04.14
(7785) 회사에 있는 사람  (0) 2026.04.14