문제
풀이
문자열의 길이를 비교하고 같다면 사전 순으로 비교하는 비교자를 만들어 정렬하였다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(string a, string b) {
if (a.length() == b.length()) return a < b;
return a.length() < b.length();
}
int main() {
int n;
string tmp;
vector<string> v;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (find(v.begin(), v.end(), s) == v.end())
v.push_back(s);
}
sort(v.begin(), v.end(), cmp);
for (int i = 0; i < v.size(); i++)
cout << v[i] << "\n";
return 0;
}