본문 바로가기
알고리즘 & 자료구조/프로그래머스

푸드 파이트 대회

by 신재권 2022. 11. 11.
package programmers;

public class 푸드파이트대회 {

   public static String solution(int[] food) {
      StringBuilder sb = new StringBuilder();
      for (int i = 1; i < food.length; i++) {
         for (int j = 1; j < food[i]; j += 2) {
            sb.append(i);
         }

      }

      String answer = sb + "0";
      answer += sb.reverse();
      return answer;
   }

   public static void main(String[] args) {
      System.out.println(solution(new int[] {1, 3, 4, 6}));
      System.out.println(solution(new int[] {1, 7, 1, 2}));
   }
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

성격 유형 검사하기  (0) 2022.11.15
숫자 짝궁  (0) 2022.11.13
콜라 문제  (0) 2022.11.10
체육복  (0) 2022.11.09
다트 게임  (0) 2022.11.08