백준
[1181] 단어 정렬
by Jcoder
2018. 7. 14.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
bool cmp(const string &a, const string &b)
{
if (a.size() == b.size())
return a < b;
return a.size() < b.size();
}
int main()
{
vector<string> v;
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string str;
cin >> str;
v.push_back(str);
}
vector<string>::iterator iter;
sort(v.begin(), v.end(), cmp);
v.erase(unique(v.begin(), v.end()), v.end());
for (iter = v.begin(); iter != v.end(); iter++)
cout << *iter << endl;
return 0;
}