일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
Tags
- C++
- Expo
- react native typescript
- c++ 정보은닉
- react native mac
- html
- 스탠실 버퍼 시작
- node.js
- react native accessible
- react
- 벡터와 리스트의 차이
- CSS
- react native typescript navigate
- react native ios 기기 연결
- 리액트 네이티브 맥
- javascript
- react native 타입스크립트
- cyworld
- GitHub
- c++ using
- react native
- 스탠실 버퍼 튜토리얼
- 스탠실 버퍼 사용
- 리액트 네이티브 설치 오류
- react native typescript navigation
- react-native
- stencil buffer
- unity stencil buffer
- node
- 싸이월드
Archives
- Today
- Total
혀니의 이거저거 뿌시기
[C++]프로그래머스 정수 내림차순으로 배치하기 본문
728x90
내코드
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
long long solution(long long n) {
vector <int>a;
long long answer = 0;
while(n / 10 != 0)
{
a.push_back(n % 10);
n = n / 10;
}
a.push_back(n % 10);
sort(a.begin(), a.end());
for (int i = a.size() - 1; i >= 0; i--)
{
answer += a.at(i);
if (i == 0)
break;
answer *= 10;
}
return answer;
}
똑똑이코드
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
long long solution(long long n) {
long long answer = 0;
string str = to_string(n);
sort(str.begin(), str.end(), greater<char>());
answer = stoll(str);
return answer;
}
wow!
숫자를 string으로 변환-> string을 char 형태로 오름차순으로 정렬 -> string을 다시 longlong으로 stoll 함수 통해 변환
728x90
'LANG > C++' 카테고리의 다른 글
[C++]08-3.가상 소멸자와 참조자의 참조 가능성 (0) | 2023.05.16 |
---|---|
[C++]08-2.가상함수(Virtual Function) (1) | 2023.05.16 |
[C++]08-1.객체 포인터의 참조관계 (0) | 2023.05.14 |
[C++]07-4.상속을 위한 조건 (0) | 2023.05.14 |
[C++]07-3.protected선언과 세 가지 형태의 상속 (0) | 2023.05.14 |