일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로그래머스
- 숫자 문자열과 영단어
- 주식 가격
- 옵셔널 체이닝 연산자
- 브루트포스 알고리즘
- react
- 10162
- 깊이 우선 탐색
- codeSyntaxHighlight
- 5525
- 4796
- 2018 KAKAO BLIND RECRUITMENT
- 위클리 챌린지
- C++
- 이분탐색
- 없는 숫자 더하기
- 구간 합 구하기 4
- 정수 삼각형
- js
- colorSyntax
- BOJ
- javascript
- n^2 배열 자르기
- Git Convention
- Hasing
- 18111
- 1620
- 다이내믹 프로그래밍
- 소수 체크
- mermaid js
Archives
- Today
- Total
개발하는 kim-hasa
[c++][BOJ][1764] 듣보잡 본문
듣도 못한 사람과 보도 못한 사람의 입력을 받아서 둘 다 속해있는 사람을 구하는 문제입니다.
먼저 듣도 못한 사람의 이름을 배열에 넣고, 보도 못한 사람의 이름이 들어올 때 마다 찾아서 같은게 있다면 정답 배열에 넣고 카운트를 증가시킵니다.
이 때, 이진 탐색을 이용해서 시간을 줄입니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> name;
vector<string> emeqh;
int ncount = 0;
void binary(int start, int end, string find){
int mid = (start + end) / 2;
if(start > end)
return ;
if(name[mid] == find)
{
ncount++;
emeqh.push_back(find);
return ;
}
if(name[mid] > find)
{
return binary(start, mid-1, find);
}
else{
return binary(mid+1, end, find);
}
}
int main(){
int n,m;
cin >> n >> m;
for(int i=0; i<n; i++){
string str1;
cin >> str1;
name.push_back(str1);
}
sort(name.begin(), name.end());
for(int j=0; j<m; j++)
{
string str2;
cin >> str2;
binary(0, n-1, str2);
}
cout << ncount << '\n';
sort(emeqh.begin(), emeqh.end());
for(int k=0; k<emeqh.size(); k++){
cout << emeqh[k] << '\n';
}
}
'Algorithm > BOJ' 카테고리의 다른 글
[c++][BOJ][1931] 회의실 배정 (0) | 2021.10.21 |
---|---|
[c++][BOJ][4796] 캠핑 (0) | 2021.10.21 |
[c++][BOJ] 통계학 (0) | 2021.10.19 |
[c++][BOJ] 수 정렬하기 3 (0) | 2021.10.19 |
[c++][BOJ] 비밀번호 찾기 (0) | 2021.10.18 |