[프로그래머스/C++]Lv.0 - 외계행성의 나이

YH J·2023년 4월 19일
0

프로그래머스

목록 보기
60/168

문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/120834

내 풀이

age를 string으로 바꾸고 'a' - '0' = (49)를 모든 원소에 더해준다

내 코드

#include <string>
#include <vector>

using namespace std;

string solution(int age) {
    string answer = "";
    
    answer = to_string(age);
    
    for(auto& s : answer)
    {
        s += 49;
    }
    
    return answer;
}

다른 사람의 풀이

#include <string>
#include <vector>
using namespace std;

string solution(int age) {
    string answer = to_string(age);

    for(auto& v : answer)
    {
        v += 'a'-'0';
    }

    return answer;
}

다른 사람의 풀이 해석

같은 풀이이다.

profile
게임 개발자 지망생

0개의 댓글