일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- ingress-nginx
- Python
- openebs
- 방통대 대학원 정보과학과
- C++
- swift
- ESXi 업데이트
- Code Jam 2022
- MySQL
- 하늘과 바람과 별과 시
- Kubernetes
- Qualification Round
- hackerrank
- 프로그래머스
- 정보과학과
- 해커랭크
- LEVEL 2
- secondlowestgrade
- 하늘과 바람과 별과 詩
- 3D PRINTING
- Code Jam
- 방송통신대학교 대학원 정보과학과
- on-prem
- GitLab
- K8S
- 파이썬
- nestedlists
- 코딩테스트
- 2022
Archives
- Today
- Total
공대생의 비망록
[프로그래머스][Lv. 2] 가장 큰 수 C++ 풀이 본문
https://programmers.co.kr/learn/courses/30/lessons/42746
코딩테스트 연습 - 가장 큰 수
0 또는 양의 정수가 주어졌을 때, 정수를 이어 붙여 만들 수 있는 가장 큰 수를 알아내 주세요. 예를 들어, 주어진 정수가 [6, 10, 2]라면 [6102, 6210, 1062, 1026, 2610, 2106]를 만들 수 있고, 이중 가장 큰
programmers.co.kr
풀이는 추후에 차차 올리도록 하겠습니다...
Swift로도 푼 문제!
Swift 풀이 : https://youngdeveloper.tistory.com/146
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool compare(int& a, int& b) {
return to_string(a) + to_string(b) > to_string(b) + to_string(a);
}
string solution(vector<int> numbers) {
vector<int>::iterator it;
sort(numbers.begin(), numbers.end(), compare);
string answer = "";
for (it = numbers.begin(); it != numbers.end(); it++) {
answer += to_string(*it);
}
while (answer.length() > 1 && answer[0] == '0') {
answer.erase(0);
}
if (answer.size() > 0) { return answer; }
else { return "0"; }
}
|
cs |
'Programming Language > C, C++' 카테고리의 다른 글
[프로그래머스][Lv. 2] 위장 C++ 풀이 (0) | 2022.05.17 |
---|---|
[프로그래머스][Lv. 2] 주식가격 C++ 풀이 (0) | 2022.05.04 |
[프로그래머스][Lv. 2] 행렬의 곱셈 C++ 풀이 (0) | 2022.05.03 |
[프로그래머스][Lv. 2] 카카오프렌즈 컬러링북 C++ 풀이 (0) | 2022.05.03 |
[C++] map 컨테이너에 데이터 추가하기 insert()? [] 연산자? (0) | 2022.05.03 |
Comments