Skip to content

Commit

Permalink
Merge pull request #20 from AlgoLeadMe/5-oesnuj
Browse files Browse the repository at this point in the history
5-oesnuj
  • Loading branch information
oesnuj authored Jun 3, 2024
2 parents 7d7e5c3 + e764051 commit df543fa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
| 2μ°¨μ‹œ | 2024.03.29 | μ—°κ²°λ¦¬μŠ€νŠΈ | [에디터](https://www.acmicpc.net/problem/1406) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/8) |
| 3μ°¨μ‹œ | 2024.04.02 | 덱 | [μΉ΄λ“œ 놓기](https://www.acmicpc.net/problem/18115) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/11) |
| 4μ°¨μ‹œ | 2024.04.06 | μŠ€νƒ | [μ˜₯상 정원 κΎΈλ―ΈκΈ°](https://www.acmicpc.net/problem/6198) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/14) |
| 5μ°¨μ‹œ | 2024.04.13 | 이뢄탐색 | [λ“£λ³΄μž‘](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) |
---
53 changes: 53 additions & 0 deletions oesnuj/이뢄탐색/1764.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;


bool binarySearch(vector <string> &v, string str) //이뢄탐색
{
int left = 0;
int right = v.size() - 1;
while (left <= right)
{
int middle = (left + right) / 2;
if (str > v[middle])
left = middle + 1;
else if (str < v[middle])
right = middle - 1;
else
return true;

}
return false;
}


int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m;
cin >> n >> m;
vector <string> v(n); //듣도 λͺ»ν•œ μ‚¬λžŒ μž…λ ₯
for (auto& i : v){
cin >> i;
}
sort(v.begin(), v.end()); //이뢄 탐색을 μœ„ν•΄ μ •λ ¬
vector <string> result;
for (int i = 0; i < m; i++)
{
string word;
cin >> word; //보도 λͺ»ν•œ μ‚¬λžŒ μž…λ ₯
if (binarySearch(v, word)){ //보도 λͺ»ν•œ μ‚¬λžŒμ΄ 듣도 보닀 λͺ»ν•œ μ‚¬λžŒμ—λ„ ν¬ν•¨λ˜λ©΄
result.push_back(word);
}
}
sort(result.begin(), result.end()); //λ§ˆμ§€λ§‰ μ‚¬μ „μˆœ 정렬을 μœ„ν•΄ μ •λ ¬

cout << result.size() << "\n";
for (const auto& word : result) {
cout << word << "\n";
}
return 0;
}

0 comments on commit df543fa

Please sign in to comment.