From 31924791b87ba7fea50fe1fa4df82336eaa25e05 Mon Sep 17 00:00:00 2001 From: gyunho <124599614+g0rnn@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:14:25 +0900 Subject: [PATCH] =?UTF-8?q?2024-11-29=20=EC=9E=A0=EC=88=98=ED=95=A8?= =?UTF-8?q?=EC=8B=9D=EB=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + g0rnn/README.md | 1 + .../8-g0rnn-2.cpp" | 36 +++++++++++++++++++ .../8-g0rnn.cpp" | 14 ++++++++ 4 files changed, 52 insertions(+) create mode 100644 "g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn-2.cpp" create mode 100644 "g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn.cpp" diff --git a/.gitignore b/.gitignore index e43b0f9..dd5c568 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +/.vscode diff --git a/g0rnn/README.md b/g0rnn/README.md index a9f8bf1..c427fa7 100644 --- a/g0rnn/README.md +++ b/g0rnn/README.md @@ -9,5 +9,6 @@ | 5차시 | 2024.11.01 | BFS/DFS | [연구소](https://www.acmicpc.net/problem/14502) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/17 | | 6차시 | 2024.11.06 | 구현 | [통계학](https://www.acmicpc.net/problem/2108) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/23 | | 7차시 | 2024.11.25 | 구현 | [팰린드롬 만들기](https://www.acmicpc.net/problem/1213) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/31 | +| 8차시 | 2024.11.29 | 문자열 | [잠수함식별](https://www.acmicpc.net/problem/2671) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/35 | --- diff --git "a/g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn-2.cpp" "b/g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn-2.cpp" new file mode 100644 index 0000000..c569ab2 --- /dev/null +++ "b/g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn-2.cpp" @@ -0,0 +1,36 @@ +#include +#include +#include +using namespace std; + +bool compareLength(string a, string b) { return a.length() < b.length(); } + +bool isStartWith(const string& str, const string& prefix) { + return str.compare(0, prefix.length(), prefix) == 0; +} + +int main() { + int n; + cin >> n; + vector prefix(n); + for (int i = 0; i < n; i++) { + cin >> prefix[i]; + } + + // Sort by string length + sort(prefix.begin(), prefix.end(), compareLength); + + int answer = n; + for (int i = 0; i < n - 1; i++) { + for (int j = i + 1; j < n; j++) { + if (isStartWith(prefix[j], prefix[i])) { + // 접두사가 있으면 i번째 단어를 없앰 + // 정렬했으니 자신보다 문자열이 긴것만 보면됨 + answer--; + break; + } + } + } + cout << answer; + return 0; +} \ No newline at end of file diff --git "a/g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn.cpp" "b/g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn.cpp" new file mode 100644 index 0000000..d77c0a5 --- /dev/null +++ "b/g0rnn/\353\254\270\354\236\220\354\227\264/8-g0rnn.cpp" @@ -0,0 +1,14 @@ +#include +#include +using namespace std; + +int main() { + string sound; + cin >> sound; + + if (regex_match(sound, regex("(100+1+|01)+"))) + cout << "SUBMARINE\n"; + else + cout << "NOISE\n"; + return 0; +} \ No newline at end of file