문자열 "aaabcabcab" sub string 중 가장 긴 중복 문자열 찾기
void max_length_duplicated_test(){
const string target = "aaabcabcab";
string max_str = "";
for(auto i=0; i<target.size();i++){
for(auto j=1; j<=target.size()-i;j++){
string sub = target.substr(i, j);
auto p = target.find(sub, i+1);
if(p != string::npos){
//cout << "FOUND : " << sub << endl;
if(max_str.size() < sub.size())
max_str = sub;
}
}
}
cout << "max str : " << max_str << endl;
}
결과
max str : abcab
'programming' 카테고리의 다른 글
C++ 에서 Rust 로 넘어가기 (c++ vs rust, Ownership) (2) | 2023.06.08 |
---|---|
Irrlicht 소개 - C++ 기반 Cross-Platform 3D 물리엔진 (0) | 2023.06.05 |
[Algorithm] C++ 문자열 조합 (combination) (2) | 2023.06.04 |
[Algorithm] C++ 미로찾기 (graph traversal ) (0) | 2023.06.03 |
[Algorithm] Graph & Tree (0) | 2023.05.30 |