cyphen156
백준-정렬 1181 단어 정렬 본문
길이순 정렬, 사전순 정렬
--> 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
'컴퓨터공학 > 알고리듬 풀이' 카테고리의 다른 글
백준-정렬 좌표 압축 (0) | 2025.04.30 |
---|---|
백준-정렬 10814 나이순 정렬 (0) | 2025.04.29 |
백준-정렬 11651 좌표 정렬하기 2 (0) | 2025.04.28 |
백준-정렬 11650 좌표 정렬하기 (0) | 2025.04.28 |
백준-정렬 1427 소트인사이드 (0) | 2025.04.28 |