백준 1181 C++

yun·2024년 1월 1일
0

C++

목록 보기
19/41
#include <iostream>
#include <string>
#include <set>

using namespace std;

int word_count;
string word;

struct sorting
{
    bool operator()(const string& a, const string& b) const
    {
        bool result;

        if (a.length() != b.length())
        {
            result = a.length() < b.length();
        }
        else
        {
            result = a < b;
        }

        return result;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> word_count;
    set<string, sorting> words;

    for (int i = 0; i < word_count; i++)
    {
        cin >> word;
        words.emplace(word);
    }

    for (string item : words)
    {
        cout << item << "\n";
    }

    return 0;
}

0개의 댓글