sort 로 풀었는데,
오늘 배운 lev31에서 슬라이딩 윈도우 사용해서 다시 해보기!
1) 슬라이딩 윈도우 사용
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int compare(string t, string v) {
if (t.length() < v.length())return 1;
if (t.length() > v.length())return 0;
return t < v;
}
int main() {
int n;
vector<string>v;
cin >> n;
for (int i = 0; i < n; i++) {
string temp;
cin >> temp;
v.push_back(temp);
}
sort(v.begin(),v.end(), compare);
for (int i = 0; i < v.size(); i++) {
cout << v[i] << "\n";
}
return 0;
}
[출력]
B
ABC
TTS
LOVE
TRUE
FRIENDS
MORETIM