안녕 세상아,

[프로그래머스/c++] Lv1 수박수박수박수박수박수? 본문

프로그래머스

[프로그래머스/c++] Lv1 수박수박수박수박수박수?

돈 많은 백수가 되고싶다 2024. 7. 31. 16:46

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

for문을 돌리며 i가 홀수일 때는 answer에 "수" 추가, 짝수일 때는 answer에 "박" 추가해준다. 

#include <string>
#include <vector>

using namespace std;

string solution(int n) {
    string answer = "";
    for(int i = 1; i <= n; i++){
        if(i%2 == 1)
            answer += "수";
        else
            answer += "박";
    }
    return answer;
}