Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 백준 2447
- c#
- 해시 구현
- 게리멘더링2
- 1764
- 백준 17779
- 백준 5397
- 조세퍼스 순열
- 해시구현
- 시간 복잡도
- dfs
- 백준 17471
- 백준 1406
- 원판 돌리기
- 자료구조
- qorwns
- 구현
- 5397
- ㅣ풀이
- 별 찍기 10
- Stack 이란
- C/C++ 구현
- 스택의 특징
- 백준 1158
- 버킷 정렬
- heap
- 백준
- 백준 17822
- 풀이
- AVL 시간 복잡도
Archives
- Today
- Total
홍시홍의 프로그래밍
[프로그래머스] 가장 큰 수 본문
분류 : 정렬
요구사항
주어진 int형 배열을 조합하여 만들 수 있는 수 중에서 가장 큰 수 찾기
풀이
int를 string으로 변환하여 내림차순으로 정렬하면 된다고 생각했으나 2번째 예제에서 실패한다 330 > 303
검색해보니
a+b > b+a 로 정렬하니 된다
앞으로 auto형도 자주 써야 되겠다
auto는 뒤에 지정한 형의 데이터로 자동으로 변환되는거 같다
auto iter만 사용했는데 for문에서도 자주사용하기
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool com(string a, string b) {
if (a + b > b + a) return true;
return false;
}
string solution(vector<int> numbers) {
string answer = "";
//int a = stoi(answer);
vector<string> v;
for (auto i : numbers)
v.push_back(to_string(i));
sort(v.begin(), v.end(),com);
for (auto i : v)
answer += i;
if (answer[0] == '0')
answer = "0";
return answer;
}
'알고리즘 문제풀이 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 튜플 (C++) (0) | 2020.05.04 |
---|---|
[프로그래머스] 섬 연결하기 (0) | 2020.04.20 |
[프로그래머스] k번째 수 (0) | 2020.04.18 |
[프로그래머스] 단어 변화 (0) | 2020.04.12 |
[프로그래머스] 네트워크 (0) | 2020.04.10 |
Comments