문제

접미사 배열 11656

"맞았습니다"코드

#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;
}

리뷰

substr() 함수로 문자열의 특정 인덱스부터 끝까지 잘라냈다.

substr(2) = 2부터 끝까지 잘라내기
substr(2,5) = 2부터 5개 잘라내기

c++ 문자열 추출 substr 함수

728x90

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

시리얼 번호 백준 1431 c++  (0) 2021.12.21
국영수 백준 10825 c++  (0) 2021.12.21
1로 만들기 백준 1463번 c++  (0) 2021.12.20
먹을것인가 먹힐것인가 백준 7795 c++  (0) 2021.12.20
빈도 정렬 백준 2910 c++  (0) 2021.12.19

+ Recent posts