728x90
반응형
- 풀이 링크:
GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이
알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.
github.com
#include <iostream>
#include <algorithm> // fill_n, min,max, swap
#include <map> // 중복 x
//#include <string> // getline
//#include <cstring> // memset, strok, strstr
//#include <vector>
//#include <queue> // priority_queue<자료형, 구현체, 비교 연산자>
//#include <set> // 트리, 중복 x
//#include <unordered_set>
//#include <cmath>
using namespace std;
/*
[백준 14425 c++ O] 문자열 집합
문제:
접근:
시간복잡도: O(n)
풀이1:
//1.입력
//2.해시맵에 저장
//3.출력: 갯수
*/
int n, m,cnt=0;
string na;
map<string, int> ma;
void input() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> na;
ma.insert({ na,1 });
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
//1.입력
input();
//2.해시맵에 저장
//3.출력: 갯수
for (int i = 0; i < m; i++) {
cin >> na;
if (ma.find(na) != ma.end()) cnt += 1;
}
cout << cnt << '\n';
return 0;
}
반응형
'Algorithm_BOJ(백준) > 해시' 카테고리의 다른 글
[백준 22252 c++ V] 정보 상인 호석 (0) | 2023.01.31 |
---|---|
[백준 19583 c++ V] 싸이버개강총회 (0) | 2023.01.29 |
[백준 4358 c++ VV] 생태학 (0) | 2023.01.29 |
[백준 1620 c++ VO] 나는야 포켓몬 마스터 이다솜 (0) | 2023.01.29 |