입출력
풀이
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
string str;
set<string> s;
cin >> str;
string part = " ";
for (int i = 0; i < str.size(); i++)
{
part = " ";
for (int j = i; j < str.size(); j++)
{
part += str[j];
s.insert(part);
}
}
cout << s.size();
return 0;
}
stl set에서는 중복된 원소가 없다는 성질을 이용한다
이중 for문으로 조합 가능한 모든 부분문자열을 만든 뒤에 set에 넣어주면 된다
'> 코딩테스트' 카테고리의 다른 글
[백준] 1735 분수 합 (C++) (0) | 2023.06.20 |
---|---|
[백준] 1269 대칭 차집합 (C++) (0) | 2023.06.17 |
[백준] 1764 듣보잡 (C++) (0) | 2023.06.15 |
[백준] 1620 나는야 포켓몬 마스터 이다솜 (C++) (0) | 2023.06.15 |
[백준] 14425 문자열 집합 (C++) (0) | 2023.06.13 |