# 생각

substr을 통해 뽑아낸 문자열을 vector에 각각 저장해준 후 정렬해주면 쉽게 해결 가능하다

 

 

# 전체 코드

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string str;
	cin >> str;
	vector<string> v;
	for (int i = 0; i < str.length(); i++)
	{
		string tmp = str.substr(i);
		v.push_back(tmp);
	}
	sort(v.begin(), v.end());
	for (auto& i : v)
	{
		cout << i << '\n';
	}
}

 


https://www.acmicpc.net/problem/11656

 

11656번: 접미사 배열

첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 1,000보다 작거나 같다.

www.acmicpc.net

'Algorithm > BOJ' 카테고리의 다른 글

[BOJ] 1463_1로 만들기 with cpp  (0) 2022.03.02
[BOJ] 10825_국영수 with cpp  (0) 2022.03.01
[BOJ] 2910_빈도 정렬 with cpp  (0) 2022.03.01
[BOJ] 1181_단어 정렬 with cpp  (0) 2022.02.28
[BOJ] 2751_수 정렬하기 2 with cpp  (0) 2022.02.28

+ Recent posts