문제
백준 11656번 접미사 배열 https://www.acmicpc.net/problem/11656
코드
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
string str;
int main() {
cin >> str;
vector<string> suffix;
int len = str.length();
for (int i = 0; i < len; i++) {
string s = str.substr(i, len);
suffix.push_back(s);
}
sort(suffix.begin(), suffix.end());
for (int i = 0; i < len; i++) cout << suffix[i] << '\n';
}
풀이방법
문자열을 입력받은 뒤에 길이별로 접미사를 만들어 벡터에 넣은 뒤, 벡터를 정렬해서 출력한다.
고민과정
약간 날먹한 느낌이라 찝찝하다
'algorithm > Sorting, Binary Search' 카테고리의 다른 글
[C++] BOJ 1026 보물 (0) | 2022.01.12 |
---|---|
[C++] BOJ 1920 수 찾기 (0) | 2021.05.08 |
[C++] BOJ 10815 숫자 카드 (0) | 2021.05.08 |
[C++] BOJ 11399 ATM (0) | 2021.05.08 |
[C++] BOJ 16401 과자 나눠주기 (0) | 2021.05.08 |