1181 - 단어 정렬

solution

code

#include <iostream>
#include <cctype>
#include <string>
#include <set>
using namespace std;

int main()
{
    int itr;
    string str;
    cin >> itr;
    set<string> strs;
    set<string>::iterator iter;
    bool check = true;
    
    // check and add to container if string is only consist of lowercase alphabet
    for(int i = 0; i < itr; i ++)
    {
        cin >> str;
        check = true;
        for(int i = 0; i < str.length(); i++)
        {
            if(!islower(str[i]))
            {
                check = false;
                break;
            }
        }
        if(check) strs.insert(str);
    }

    // print container
    for (int i = 1; i <= 50; i++)
    {
        for(iter = strs.begin(); iter != strs.end(); iter++)
            if(iter->length() == i)
                cout << *iter << endl;
    }
    return 0;
}

ref

1181번: 단어 정렬