# 문제
# 입력 및 출력
# 풀이
map을 사용해서 간단하게 풀었음
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
map<string, int> p;
vector<string> result;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m, cnt = 0;
cin >> n >> m;
string t;
while (n--) {
cin >> t;
p[t] = 1;
}
while (m--) {
cin >> t;
if (p[t]) {
cnt++;
result.push_back(t);
}
}
sort(result.begin(), result.end());
cout << cnt << "\n";
for (auto i : result) {
cout << i << "\n";
}
}
정렬해서 사전순으로 출력해야하는데 정렬을 안해줘서 한번 틀렸음ㅋㅋ
풀고 다른사람 코드 둘러보다가 auto를 발견했는데 좋아보여서 써봄
코틀린에서 var같은 느낌이랄까
https://dydtjr1128.github.io/cpp/2019/06/04/Cpp-auto.html
C++ auto란? - dydtjr1128's Blog
auto? 1. Intro C++ 표준에 기록되어 있는 auto라는 키워드는 원래 의미와 수정된 의미가 정의되어 있다. C++11전에는 auto는 자동 저장소 클래스에...
dydtjr1128.github.io
'Algorithm > 📖Baekjoon' 카테고리의 다른 글
# 11478 서로 다른 부분 문자열의 개수 (0) | 2022.05.21 |
---|---|
#1269 대칭 차집합 (0) | 2022.05.20 |
#10816 숫자 카드 2 (0) | 2022.05.18 |
#1620 나는야 포켓몬 마스터 이다솜 (0) | 2022.05.17 |
#14425 문자열 집합 (0) | 2022.05.16 |
댓글