본문 바로가기
C++

[프로그래머스] 가위 바위 보

by 띰쥬 2025. 9. 5.
728x90
반응형
SMALL

#include <string>
#include <vector>

using namespace std;

string solution(string rsp) {
    string answer = "";
    //가위 2, 바위 0, 보 5
    
    for(char hand : rsp){
        if(hand == '0') answer+='5';
        else if(hand == '2') answer+='0';
        else if(hand == '5') answer+='2';
    }
        
    return answer;
}

 

 

해당 케이스는 짧아서 괜찮지만 'hand'와 같은 조건이 많아지면 switch~case문을 사용하는것이 효율적인 측면에서 좋음

728x90
반응형
LIST

댓글