백준/백준-C++

1181번: 단어 정렬

Beabletoet 2017. 6. 11. 12:52

#include<iostream>

#include<algorithm>

#include<string>

using namespace std;

bool compare(const string &a, const string &b)

{

return a.length() < b.length();

}

int main()

{

int n;

string word[20000];

cin >> n;

for (int i = 0; i < n; ++i)

cin >> word[i];

sort(&word[0], &word[n]);

stable_sort(&word[0], &word[n], compare);

cout << word[0] << endl;

for (int i = 1; i < n; ++i)

if(word[i] != word[i-1])

cout << word[i] << endl;

}