11656번: 접미사 배열
첫째 줄에 문자열 S가 주어진다. S는 알파벳 소문자로만 이루어져 있고, 길이는 1,000보다 작거나 같다.
www.acmicpc.net
배운 것
문자열 자르기 연습
substr()
문자열.substr(시작 위치, 길이)
- 첫 번째 인수에는 시작 위치를, 두 번째 인수에는 취득하고 싶은 문자수를 지정
- 문자열 시작은 0부터
#include <iostream>
using namespace std;
int main() {
string str1 = "abcde";
cout << str1.substr(0, 1) << endl; // a
cout << str1.substr(1, 1) << endl; // b
cout << str1.substr(2, 1) << endl; // c
cout << str1.substr(0, 2) << endl; // ab
cout << str1.substr(1, 2) << endl; // bc
return 0;
}
정답 코드
// Authored by : std-freejia
// Co-authored by : -
//http://boj.kr/21378a10916b42d19dce4bc7c841a73c
#include <bits/stdc++.h>
using namespace std;
string st;
vector<string> v;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> st;
int stringlen = st.length();
for(int i = 0; i < stringlen; i++) {
string temp = st.substr(i);
v.push_back(temp);
}
sort(v.begin(), v.end());
for(auto i : v) cout << i << '\n';
return 0
'Algorithm > C++' 카테고리의 다른 글
[백준 2910] 빈도 정렬 (0) | 2022.10.04 |
---|---|
[백준 7795] 먹을 것인가 먹힐 것인가 (0) | 2022.10.04 |
[백준 10814] 나이순 정렬 (0) | 2022.10.04 |
[백준 1181] 단어 정렬 (0) | 2022.09.28 |
[백준 15663] N과 M(9) (0) | 2022.09.28 |
댓글