diff --git a/caucsejunseo/README.md b/caucsejunseo/README.md index 2267737..f576f01 100644 --- a/caucsejunseo/README.md +++ b/caucsejunseo/README.md @@ -9,4 +9,5 @@ | 5차시 | 2025.04.02 | 큐 | [요세푸스문제](https://www.acmicpc.net/problem/1158)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/19| | 6차시 | 2025.04.06 | 큐 | [앵무새](https://www.acmicpc.net/problem/14713)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/23| | 7차시 | 2025.04.10 | 그리디 | [폴리오미노](https://www.acmicpc.net/problem/1343)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/28| - | 8차시 | 2025.04.11 | 연결리스트| [키로거](https://www.acmicpc.net/problem/5397)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/30| +| 8차시 | 2025.04.11 | 연결리스트| [키로거](https://www.acmicpc.net/problem/5397)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/30| +| 9차시 | 2025.04.30 | 문자열 | [듣보잡](https://www.acmicpc.net/problem/1764)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/35| \ No newline at end of file diff --git "a/caucsejunseo/\354\236\220\353\243\214 \352\265\254\354\241\260/2025.03.22.\353\213\250\354\226\264\353\222\244\354\247\221\352\270\2602.c" "b/caucsejunseo/\353\254\270\354\236\220\354\227\264/2025.03.22.\353\213\250\354\226\264\353\222\244\354\247\221\352\270\2602.c" similarity index 100% rename from "caucsejunseo/\354\236\220\353\243\214 \352\265\254\354\241\260/2025.03.22.\353\213\250\354\226\264\353\222\244\354\247\221\352\270\2602.c" rename to "caucsejunseo/\353\254\270\354\236\220\354\227\264/2025.03.22.\353\213\250\354\226\264\353\222\244\354\247\221\352\270\2602.c" diff --git "a/caucsejunseo/\353\254\270\354\236\220\354\227\264/2025.04.30.\353\223\243\353\263\264\354\236\241.c" "b/caucsejunseo/\353\254\270\354\236\220\354\227\264/2025.04.30.\353\223\243\353\263\264\354\236\241.c" new file mode 100644 index 0000000..87393c0 --- /dev/null +++ "b/caucsejunseo/\353\254\270\354\236\220\354\227\264/2025.04.30.\353\223\243\353\263\264\354\236\241.c" @@ -0,0 +1,177 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include + +#define LINE 21 +#define MAX 500000 + +typedef struct Nolisten { + + char name[LINE]; + +} Nolisten; + +typedef struct Nosee { + + char name[LINE]; +}Nosee; + +typedef struct Nolistenandsee { + + char name[LINE]; + +} Nolistenandsee; + +// strcmp 기반 구조체 비교 함수 +int compare_struct(const void* a, const void* b) { + return strcmp(((Nolisten*)a)->name, ((Nolisten*)b)->name); +} + + +int main(void) { + + int N = 0; + int M = 0; + int count = 0; + + + scanf("%d", &N); + scanf("%d", &M); + getchar(); + + //구조체 메모리 공간 할당 + Nolisten* nolistenlist = malloc(sizeof(Nolisten) * N); + Nosee* noseelist = malloc(sizeof(Nosee) * M); + Nolistenandsee* nolistenandseelist = malloc(sizeof(Nolistenandsee) * MAX); + + + //입력받기 + for (int i = 0; i < N; i++) + { + fgets(nolistenlist[i].name, LINE, stdin); + nolistenlist[i].name[strcspn(nolistenlist[i].name, "\n")] = '\0'; // 개행 제거 + } + for (int j = 0; j < M; j++) + { + fgets(noseelist[j].name, LINE, stdin); + noseelist[j].name[strcspn(noseelist[j].name, "\n")] = '\0'; // 개행 제거 + } + + //듣도보도 못한 놈인지 확인 + qsort(nolistenlist, N, sizeof(Nolisten), compare_struct); + + for (int j = 0; j < M; j++) + { + Nolisten key; + strcpy(key.name, noseelist[j].name); + + Nolisten* found = bsearch(&key, nolistenlist, N, sizeof(Nolisten), compare_struct); + if (found != NULL) { + strcpy(nolistenandseelist[count++].name, key.name); + } + } + + qsort(nolistenandseelist, count, sizeof(Nolistenandsee), compare_struct); + + // 정답 출력 + printf("%d\n", count); + for (int i = 0; i < count; i++) { + printf("%s\n", nolistenandseelist[i].name); + } + + + return 0; +} + +// 시간초과 코드 +/*#define _CRT_SECURE_NO_WARNINGS + #include + # include + #include + +#define LINE 21 +#define MAX 500000 + +typedef struct Nolisten { + + char name[LINE]; + +} Nolisten; + +typedef struct Nosee { + + char name[LINE]; +}Nosee; + +typedef struct Nolistenandsee { + + char name[LINE]; + +} Nolistenandsee; + +int compare_name(const void* a, const void* b) { + const Nolistenandsee* na = (const Nolistenandsee*)a; + const Nolistenandsee* nb = (const Nolistenandsee*)b; + return strcmp(na->name, nb->name); +} + +int main(void) { + + int N = 0; + int M = 0; + int count = 0; + + + scanf("%d", &N); + scanf("%d", &M); + getchar(); + + //구조체 메모리 공간 할당 + Nolisten* nolistenlist = malloc(sizeof(Nolisten) * N); + Nosee* noseelist = malloc(sizeof(Nosee) * M); + Nolistenandsee* nolistenandseelist = malloc(sizeof(Nolistenandsee) * MAX); + + + //입력받기 + for (int i = 0; i < N; i++) + { + fgets(nolistenlist[i].name, LINE, stdin); + nolistenlist[i].name[strcspn(nolistenlist[i].name, "\n")] = '\0'; // 개행 제거 + } + for (int j = 0; j < M; j++) + { + fgets(noseelist[j].name, LINE, stdin); + noseelist[j].name[strcspn(noseelist[j].name, "\n")] = '\0'; // 개행 제거 + } + + //듣도보도 못한 놈인지 확인 + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if (strlen(nolistenlist[i].name) == strlen(noseelist[j].name)) + { + if (strcmp(nolistenlist[i].name, noseelist[j].name) == 0) + { + strcpy(nolistenandseelist[count].name, nolistenlist[i].name); + count++; + + } + } + } + } + + // 듣보잡 이름 정렬 + qsort(nolistenandseelist, count, sizeof(Nolistenandsee), compare_name); + + // 정답 출력 + printf("%d\n", count); + for (int i = 0; i < count; i++) { + printf("%s\n", nolistenandseelist[i].name); + } + + + return 0; +} +*/ \ No newline at end of file