문제
접근 방법
모든 부분 문자열을 추출한 후 이를 반복되는지 확인해야 함
이 과정은 C++의 set 함수를 사용해서 처리
코드
#include <iostream>
#include <set>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string S;
cin >> S;
set<string> s;
for (int i = 0; i < S.length(); i++) {
string tmp = "";
for (int j = i; j < S.length(); j++) {
tmp += S[j];
s.insert(tmp);
}
}
cout << s.size();
return 0;
}
링크
'Algorithm(C++)' 카테고리의 다른 글
[BOJ - 5430] AC(C++) (0) | 2025.02.10 |
---|---|
[BOJ - 5397] 키로거(C++) (0) | 2025.02.08 |