카테고리 없음
[프로그래머스 C++] 외계행성의 나이
AKI(JUNI)
2024. 3. 12. 23:10
◈ 문제 설명
◈ 문제 설명 링크
코딩테스트 연습 - 외계행성의 나이 | 프로그래머스 스쿨 (programmers.co.kr)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
◈ 작성 코드
#include <string>
#include <vector>
using namespace std;
string solution(int age)
{
string answer = "";
vector<string> finds = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
if(age >= 1 && age < 10)
{
answer = finds[age];
}
else if(age >= 10 && age < 100)
{
int a = age / 10;
int b = age % 10;
answer = finds[a] + finds[b];
}
else if(age >= 100 && age < 1000)
{
int a = age / 100;
int b = age % 100;
int c = b / 10;
int d = b % 10;
answer = finds[a] + finds[c] + finds[d];
}
else
{
answer = "baaa";
}
return answer;
}