알고리즘/자료구조
BOJ)11656 접미사 배열(다시 보기)
광그로
2017. 6. 20. 06:37
https://www.acmicpc.net/problem/11656
s.c_str() : string의 시작 주소를 반환
s.substr(pos, length) : string의 pos부터 시작하여, length까지를 string으로 return
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <iostream> #include <string> #include <cstring> #include <vector> #include <algorithm> using namespace std; string s; bool comp(int x, int y) { return strcmp(s.c_str() + x, s.c_str() + y) < 0; } int main() { cin >> s; vector <int> t; for (int i = 0; i < s.size(); i++) { t.push_back(i); } int a; int b; sort(t.begin(), t.end(), comp); for (int i = 0; i < t.size(); i++) { cout << s.substr(t[i]) << "\n"; } return 0; } | cs |