https://www.acmicpc.net/problem/1181
#include <iostream>
#include <vector>
#include <algorithm>
#define endl "\n"
using namespace std;
bool compare(string a, string b) {
if (a.size() == b.size()) return a < b;
else return a.size() < b.size();
}
int main(void) {
// C++ Init
ios::sync_with_stdio(false);
cin.tie(NULL);
int input;
string str;
vector<string> v;
cin >> input;
for (int i = 0; i < input; i++) {
cin >> str;
v.push_back(str);
}
// 벡터 중복값 제거
// 1. 벡터 요소 정렬
sort(v.begin(), v.end());
// 벡터 중복 값 제거
// 2. 벡터 값 삭제
v.erase(unique(v.begin(), v.end()), v.end());
// 벡터 사용자 알고리즘 정렬
sort(v.begin(), v.end(), compare);
for (int i = 0; i < v.size(); i++) {
cout << v[i] << endl;
}
}
벡터 중복값 제거
벡터 사용자 정렬
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 1676 팩토리얼 0의 개수 (0) | 2024.12.29 |
---|---|
C++ 알고리즘 - 백준 1436 영화감독 숌 (0) | 2024.12.29 |
C++ 알고리즘 - 백준 28702 FizzBuzz (0) | 2024.12.28 |
C++ 알고리즘 - 백준 11050 이항 계수 1 (0) | 2024.12.28 |
C++ 알고리즘 - 백준 10989 수 정렬하기 3 (계수 정렬) (0) | 2024.12.28 |