cgy12306

[백준 BoJ] 16496 - 큰 수 만들기 본문

Algorithm/C++

[백준 BoJ] 16496 - 큰 수 만들기

cgy12306 2021. 11. 26. 17:11
// https://www.acmicpc.net/problem/16496
// 큰 수 만들기
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

bool cmp(string a, string b) {
	return a + b > b + a;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int N;
	vector<string> vs;

	cin >> N;

	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		vs.push_back(s);
	}

	sort(vs.begin(), vs.end(), cmp);
	string res;
	for (int i = 0; i < vs.size(); i++) {
		res += vs[i];
	}
	if (vs[0] == "0") cout << "0";
	else cout << res;
}

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

[백준 BoJ] 6588 - 골드바흐의 추측  (0) 2021.12.01
[백준 BoJ] 4948 - 베르트랑 공준  (0) 2021.12.01
[백준 BoJ] 17141 - 연구소 2  (0) 2021.11.21
[백준 BoJ] 3079 - 입국심사  (0) 2021.10.23
[백준 BoJ] 14502 - 연구소  (0) 2021.10.23
Comments