Skip to content

Instantly share code, notes, and snippets.

@dev-yong
Created February 8, 2017 15:30
Show Gist options
  • Save dev-yong/785631ffeb8ba5289b5bd3e5de9f7db8 to your computer and use it in GitHub Desktop.
Save dev-yong/785631ffeb8ba5289b5bd3e5de9f7db8 to your computer and use it in GitHub Desktop.
문자열 + 이진탐색
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
#define MAX_N 500001
char hear[MAX_N][21];
char see[21];
char hearsee[MAX_N][21];
int cmp(const void *a, const void *b) {
return strcmp((char *)a, (char *)b);
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", hear[i]);
}
qsort(hear, n, sizeof(hear[0]), cmp);
int cnt = 0;
for (int i = 0; i < m; i++) {
scanf("%s", see);
if (bsearch(see, hear, n, 21, cmp) != NULL) {
strcpy(hearsee[cnt++],see);
}
}
qsort(hearsee, cnt, sizeof(hearsee[0]), cmp);
printf("%d\n", cnt);
for (int i = 0; i < cnt; i++) {
printf("%s\n", hearsee[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment