백준 algorithm
백준 11656 - 접미사 배열
cosmohoo
2020. 3. 13. 12:25
반응형

=> substr 함수의 사용을 할줄 아는지 묻는 문제이다.
=> string이 들어가 있는 배열 역시 sort함수를 통해 정렬 할 수 있다. (연산자 재정의 no need)
=> for문을 쓸 경우 length()같은 함수를 for문에 쓸 경우 시간이 더 걸리게 된다. 그 이전에 int limit = s.length() 를 해주어야 시간을 save 할 수 있게 된다.
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s;
cin>>s;
vector<string> arr;
int limit=s.length();
for(int i=0; i<limit; ++i)
{
arr.push_back(s.substr(i));
}
sort(arr.begin(), arr.end());
for(int i=0; i<limit; ++i)
{cout<<arr[i]<<'\n';}
return 0;
}
반응형