728x90
SMALL

using System;

public class Solution {
    public string solution(string rsp) {
        string answer = "";
        // 2 > 0
        // 0 > 5
        // 5 > 2
        for(int i=0;i<rsp.Length;i++)
        {
            if(rsp[i].ToString() == "2")
            {
                answer += "0";
            }
            else if(rsp[i].ToString() == "0")
            {
                answer += "5";
            }
            else
            {
                answer += "2";
            }
        }
        
        return answer;
    }
}

 

파이썬

 

////

def solution(rsp):
    rsp =rsp.replace('2','s')
    rsp =rsp.replace('5','p')
    rsp =rsp.replace('0','r')
    rsp =rsp.replace('r','5')
    rsp =rsp.replace('s','0')
    rsp =rsp.replace('p','2')
    return rsp

/////

 

def solution(rsp):
    answer = ''
    for i in list(map(int, rsp)):
        if i == 0:
            answer += str(5)
        elif i == 2:
            answer += str(0)
        else:
            answer += str(2)
    return answer

 

 

자바

 

 

class Solution {
    public String solution(String rsp) {
        char[] cRsp = rsp.toCharArray();
        StringBuilder answer = new StringBuilder();

        for(int i=0; i < cRsp.length; i++) 
        {
            switch(cRsp[i]) 
            {
                case '0' :
                    answer.append("5");
                    break;
                case '2' :
                    answer.append("0");
                    break;
                case '5' :
                    answer.append("2");
                    break;
            }
        }
        
        return answer.toString();

    }
}

 

 

class Solution {
    public String solution(String rsp) {
        String answer = "";
        String[] arr = rsp.split("");
        
        for(int i=0;i < arr.length; i++) 
        {
            if(arr[i].equals("2")) 
              answer += "0";
            else if(arr[i].equals("0")) 
              answer += "5";
            else
              answer += "2";
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글