알고리즘 · 코딩
[SWEA 1256] K번째 접미어
G A
2021. 1. 1. 23:21
문제 링크
swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV18GHd6IskCFAZN#none
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
C++ 풀이
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
for (int i = 1; i <= T; i++) {
int K;
cin >> K;
string word;
vector <string> words;
cin >> word;
int wordSize = word.length();
for (int i = 0; i < wordSize; i++)
words.emplace_back(word.substr(i, wordSize - i));
sort(words.begin(), words.end());
if (K > wordSize)
cout << "#" << i << " none\n";
else
cout << "#" << i << " " << words[K - 1] << "\n";
}
return 0;
}
벡터에 원소 삽입 시 push_back 외에 emplace_back이 있다는 것과, 그 둘의 차이점을 배웠다.
반응형