관리 메뉴

cyphen156

백준-정렬 1181 단어 정렬 본문

컴퓨터공학/알고리듬 풀이

백준-정렬 1181 단어 정렬

cyphen156 2025. 4. 28. 17:07

단어 정렬

길이순 정렬, 사전순 정렬

--> 2계층 정렬

중복은 제거한다.

제약사항

  • 1 ≤ N ≤ 20,000
  • 0 < strlen <= 50

주의 사항

없다.

CPP풀이

단어 정렬_1181.cpp

/**
 * 백준 단어 정렬_1181
 * 길이순 정렬, 사전순 정렬
 * --> 2계층 정렬
 * 중복은 제거한다.
 * 
 * 제한사항
 *****************************************
 * 1 ≤ N ≤ 20,000                        *
 * 0 < strlen <= 50                      *
 *****************************************
 *
 *
 *
 * 주의
 * 없다.
 * 
 * 풀이시간 20분
 */


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N;
    cin >> N;


    vector<string> strVec[51];

    for (int i = 0; i < N; ++i)
    {
        string str;
        cin >> str;
        strVec[str.length()].push_back(str);
    }

    // 정렬할래?
    for (int i = 0; i < 51; ++i)
    {
        if (strVec[i].size() != 0)
        {
            sort(strVec[i].begin(), strVec[i].end());
            strVec[i].erase(unique(strVec[i].begin(), strVec[i].end()), strVec[i].end());
            for (int j = 0; j < strVec[i].size(); ++j)
            {
                cout << strVec[i][j] << '\n';
            }
        }
    }

    return 0;
}

모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리 에 있습니다.

 

Workspace/알고리듬 풀이 at main · cyphen156/Workspace

Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.

github.com