본문 바로가기

알고리즘/BOJ

[C++] 백준 11656번 - 접미사 배열


0. 문제

 

 

1. 아이디어

 

1) 접미사들을 vector에 넣어서 sort 함수를 이용해서 정렬한 뒤 출력한다!

 

2. 소스코드

 

#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
	std::vector<std::string> v;
	std::string str;
	std::cin >> str;
	
	for (int i = 0; i < str.length(); i++)
		v.push_back(str.substr(i));

	sort(v.begin(), v.end());

	for (int i = 0; i < v.size(); i++)
		std::cout << v[i] << '\n';
}

 

3. 결과

 

 

4. 피드백

 

  • string을 공부하자.... 공부할게 늘어난다 늘어나.


 

TO DO LIST: string


 

'알고리즘 > BOJ' 카테고리의 다른 글

[C++] 백준 1168번 - 요세푸스 문제 2  (0) 2020.04.14
[C++] 백준 11655번 - ROT13  (0) 2020.03.30
[C/C++] 문자 입력 함수 정리  (0) 2020.03.30
[C++] 백준 11004번 - K번째 수  (0) 2020.03.29
[C++] 백준 11652번 - 카드  (0) 2020.03.29