일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 코딩테스트
- 주정부이민
- 딥러닝
- Deep learning
- leetcode
- mpnp
- 선형대수
- 마니토바
- 온라인석사
- LV1
- 머신러닝
- 개발자
- 프로그래머스
- 방통대
- LAA
- 방송통신대학교
- Plotting
- cpp
- zeros
- 컴퓨터과학과
- 매트랩
- 알고리즘
- 캐나다 영주권
- MATLAB
- C++
- 조지아텍
- machine learning
- 기본
- EOI
- omscs
Archives
- Today
- Total
Krononberg
프로그래머스) 3진법 뒤집기 c++ 본문
핵심 : 진법 변환 연습.
배운 것 : vector를 썼다면, to_string과 y[i]-0을 생략할 수 있었겠다.
#include <string>
#include <vector>
#include <math.h>
using namespace std;
string convertToTernary(int& x){
string s = "";
while(x!=0){
s += to_string(x % 3);
x /= 3;
}
return s;
}
int convertToDecimal(string y){
int decimal = 0;
for(int i =0; i < y.size(); i++) decimal += (y[i]-'0')*pow(3,y.size()-(i+1));
return decimal;
}
int solution(int n) {
return convertToDecimal(convertToTernary(n));
}
'개발 로그 > 알고리즘' 카테고리의 다른 글
프로그래머스) 문자열 내 p와 y의 개수 c++ (0) | 2021.09.03 |
---|---|
프로그래머스) 문자열 다루기 기본 c++ (0) | 2021.09.03 |
프로그래머스) 실패율 c++ (0) | 2021.09.02 |
프로그래머스) 행렬의 덧셈. 파이썬 (0) | 2021.09.01 |
프로그래머스) 찾아라 프로그래밍 마이스터 c++ (0) | 2021.08.31 |