◈ 문제 설명
◈ 문제 설명 링크
코딩테스트 연습 - 3진법 뒤집기 | 프로그래머스 스쿨
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
◈ 작성 코드
#include <string>
#include <vector>
using namespace std;
int solution(int n)
{
int answer = 0;
vector<int> ace;
while(n)
{
ace.push_back(n % 3);
n /= 3;
}
int a = 1;
for(int i = ace.size() - 1; i >= 0; i--)
{
answer += ace[i] * a;
a *= 3;
}
return answer;
}
'[프로그래머스 C++] > LEVEL 1' 카테고리의 다른 글
[프로그래머스 C++] 모의고사 (0) | 2025.03.31 |
---|---|
[프로그래머스 C++] 두 개 뽑아서 더하기 (0) | 2025.03.31 |
[프로그래머스 C++] 내적 (0) | 2024.04.24 |
[프로그래머스 C++] 신규 아이디 추천 (0) | 2024.04.24 |
[프로그래머스 C++] 음양 더하기 (0) | 2024.04.24 |