Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 알고리즘
- 컴공과
- 정석학술정보관
- 정석
- vector
- 그래프
- 오에스
- 오퍼레이팅시스템
- 개발
- cs
- DP
- Computer science
- Operating System
- 구현
- 코테
- OS
- 백준
- bfs
- 컴퓨터공학과
- coding
- c++
- 자료구조
- 북리뷰
- 브루트포스
- Stack
- 스택
- 컴공
- 너비우선탐색
- 문제풀이
- 코딩
Archives
- Today
- Total
Little Jay
[C++] 백준 1764번 - 듣보잡 본문
마지막에 조건으로 이름을 사전순으로 출력해야 되는것을 제대로 못보고
왜 틀렸는지 하루종일 보고 있었다.....
일단 맵이나 해쉬로 풀지 않았다.
이거 같은 경우는 그냥 벡터를 계속 정렬해주면서
binary_search로 빠르게 이름을 찾으면 되는 문제인 것 같다.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> v(n);
v.resize(n);
string s;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
vector<string> temp;
for (int i = 0; i < m; i++) {
cin >> s;
if (binary_search(v.begin(), v.end(), s))
temp.push_back(s);
}
cout << temp.size() << "\n";
sort(temp.begin(), temp.end());
for (int i = 0; i < temp.size(); i++) {
cout << temp[i] << "\n";
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 4889번 - 안정적인 문자 (0) | 2021.08.17 |
---|---|
[C++] 백준 7568번 - 덩치 (0) | 2021.08.17 |
[C++] 백준 1620 - 나는야 포켓몬 마스터 이다솜 (0) | 2021.08.17 |
[C++] 백준 11659 - 구간 합 구하기 4 (0) | 2021.08.16 |
[C++] 백준 11399번 - ATM (0) | 2021.08.16 |
Comments