Skip to content

Commit

Permalink
2024-11-29 잠수함식별
Browse files Browse the repository at this point in the history
  • Loading branch information
g0rnn committed Nov 28, 2024
1 parent d5d7e37 commit 3192479
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
/.vscode
1 change: 1 addition & 0 deletions g0rnn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

---
36 changes: 36 additions & 0 deletions g0rnn/문자열/8-g0rnn-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <algorithm>
#include <iostream>
#include <vector>
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<string> 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;
}
14 changes: 14 additions & 0 deletions g0rnn/문자열/8-g0rnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <regex>
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;
}

0 comments on commit 3192479

Please sign in to comment.