cgy12306

[백준 BoJ] 1181 - 단어 정렬 본문

Algorithm/C++

[백준 BoJ] 1181 - 단어 정렬

cgy12306 2021. 4. 14. 19:26
// https://www.acmicpc.net/problem/1181
// 단어 정렬 

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

bool size_compare(string a, string b) {
	if (a.size() == b.size()) return a < b;
	return a.size() < b.size();
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cin.tie(NULL);

	int N;
	string s;
	vector <string> v;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> s;
		v.push_back(s);
	}
	sort(v.begin(), v.end(), size_compare);
	v.erase(unique(v.begin(), v.end()), v.end());
	
	for (auto i = v.begin(); i != v.end(); ++i) {
		cout << *i <<"\n";
	}
}

'Algorithm > C++' 카테고리의 다른 글

[백준 BoJ] 1978 - 소수 찾기  (0) 2021.04.14
[백준 BoJ] 1920 - 수 찾기  (0) 2021.04.14
[백준 BoJ] 1929 - 소수 구하기  (0) 2021.04.14
[백준 BoJ] 11057 - 오르막 수  (0) 2021.04.08
[백준 BoJ] 9465 - 스티커  (0) 2021.04.08
Comments