728x90
SMALL

using System;

public class Solution {
    public long solution(string numbers) {
        long answer = 0;
        string answe = "";
        
        numbers = numbers.Replace("zero", "0");
        numbers = numbers.Replace("one", "1");
        numbers = numbers.Replace("two", "2");
        numbers = numbers.Replace("three", "3");
        numbers = numbers.Replace("four", "4");
        numbers = numbers.Replace("five", "5");
        numbers = numbers.Replace("six", "6");
        numbers = numbers.Replace("seven", "7");
        numbers = numbers.Replace("eight", "8");
        answe = numbers.Replace("nine", "9");
        
        answer = long.Parse(answer);
        
        return answer;
    }
}

 

///

using System;

public class Solution {
    public long solution(string numbers) {
        long answer = 0;
        string[] numString = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        for(int i=0;i<numString.Length;i++)
        {
            numbers = numbers.Replace(numString[i],i.ToString());
        }
        return long.Parse(numbers);
    }
}

 

파이썬

/////

def solution(numbers):
    for num, eng in enumerate(["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]):
        numbers = numbers.replace(eng, str(num))
    return int(numbers)

 

자바

//////

 

class Solution {
    public long solution(String numbers) {
        return Long.parseLong(
                numbers.replaceAll("zero", "0")
                        .replaceAll("one", "1")
                        .replaceAll("two", "2")
                        .replaceAll("three", "3")
                        .replaceAll("four", "4")
                        .replaceAll("five", "5")
                        .replaceAll("six", "6")
                        .replaceAll("seven", "7")
                        .replaceAll("eight", "8")
                        .replaceAll("nine", "9")
        );
    }
}

 

 

class Solution {
    public long solution(String numbers) {

            String[] numbers_arr = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

            for (int i = 0; i < numbers_arr.length; i++) 
            {
                numbers = numbers.replaceAll(numbers_arr[i], String.valueOf(i));
            }

            long answer = Long.parseLong(numbers);
            return answer;
        }
}
728x90

설정

트랙백

댓글