문제
가위는 2 바위는 0 보는 5로 표현합니다. 가위 바위 보를 내는 순서대로 나타낸 문자열 rsp가 매개변수로 주어질 때, rsp에 저장된 가위 바위 보를 모두 이기는 경우를 순서대로 나타낸 문자열을 return하도록 solution 함수를 완성해보세요.
솔루션
#include <string>
#include <vector>
using namespace std;
string solution(string rsp) {
string answer = "";
for(int i = 0; i < rsp.size(); i++){
if(rsp[i] == '0'){
answer += "5";
}
else if(rsp[i] == '2'){
answer += "0";
}
else if(rsp[i] == '5'){
answer += "2";
}
}
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/120839
'프로그래머스코딩테스트연습풀이 > C++' 카테고리의 다른 글
[프로그래머스/C++] 최댓값 만들기 (2) (0) | 2025.02.13 |
---|---|
[프로그래머스/C++] 숨어있는 숫자의 덧셈 (1) (0) | 2025.02.13 |
[프로그래머스/C++] 개미 군단 (0) | 2025.02.13 |
[프로그래머스/C++] 직각삼각형 출력하기 (0) | 2025.02.13 |
[프로그래머스/C++] 옷가게 할인 받기 (0) | 2025.02.13 |