728x90
SMALL

using System;
using System.Linq;

public class Solution {
    public string solution(int[] food) {
        string answer = "";
        int times = 0;
        
        for(int i = 1; i<food.Length;i++)
        {
            times = food[i]/2;
            
            for(int j = 0;j<times;j++)
            {
                answer += i;    
            }
        }
        
        answer += 0;
        
        for(int i = food.Length-1; i>0;i--)
        {
            times = food[i]/2;
            
            for(int j = 0;j<times;j++)
            {
                answer += i;    
            }
        }
        
        return answer;
    }
}

 

////////////////

 

using System;
using System.Linq;

public class Solution {
    public string solution(int[] food) {
        string answer = "0";
        int times = 0;
        
        for (int i = food.Length - 1; i > 0; i--) 
        {
            for (int j = 0; j < food[i] / 2; j++) 
            {
                answer = i + answer + i; 
            }
        }

        return answer;
    }
}

 

 

using System;
using System.Collections.Generic;
public class Solution
{
    public string solution(int[] food)
    {
        string answer = "";
        for(int i = 1; i < food.Length; i++)
        {
            int nowCount = food[i] / 2;
            for(int count = 0; count < nowCount; count++)
            {
                answer += i.ToString();
            }
        }
        char[] temp = answer.ToCharArray();
        Array.Reverse(temp);
        string back = new string(temp);
        answer += "0" + back;
        return answer;
    }
}

 

 

파이썬

/////

 

def solution(food):
    answer ="0"
    for i in range(len(food)-1, 0,-1):
        c = int(food[i]/2)
        while c>0:
            answer = str(i) + answer + str(i)
            c -= 1
    return answer

 

////

 

def solution(food):
    answer = ''
    rev=''
    for i in range(1,len(food)):
        answer+=str(i)*(food[i]//2)
    rev=answer[::-1]
    answer+='0'

    return answer+rev

 

자바

/////

 

class Solution {
    public String solution(int[] food) {
        String answer = "0";

        for (int i = food.length - 1; i > 0; i--) 
        {
            for (int j = 0; j < food[i] / 2; j++) 
            {
                answer = i + answer + i; 
            }
        }

        return answer;
    }
}

 

 

728x90

설정

트랙백

댓글