목록분류 전체보기 (150)
코딩응급실
import java.util.Stack; class Solution { public int solution(int[] ingredient) { int answer = 0; Stack stack = new Stack(); for (int i : ingredient) { stack.push(i); // 스택 길이가 4이상이면 바로 검사 if (stack.size() >= 4) { /* 현재 사이즈에서 4칸 밑으로 내려가서 get한 값이 1(빵)이고, 3칸 밑으로 내려가서 get한 값이 2(야채)이고, 2칸 밑으로 내려가서 get한 값이 3(고기)이고, 1칸 밑으로 내려가서 get한 값이 1(빵)이면 게살버거 완성! ???: 따하하하핳~ x 2 징징아, 게살버거 나왔어♥ */ if (stack.get(sta..
import java.util.HashMap; class Solution { public int solution(String[] friends, String[] gifts) { int answer = 0; int friendsLenght = friends.length; // 해시맵 생성 문자열, 정수 HashMap dic = new HashMap(); // 선물 지수 배열 int[] giftDegree = new int[friendsLenght]; // 주고받은 선물지수의 표 int[][] giftGraph = new int[friendsLenght][friendsLenght]; // dic이란 맵에 친구들의 이름, 인덱스를 받는다. for ( int i = 0; i < friendsLenght; i++..
import java.util.*; class Solution { public String solution(int[] food) { String answer = ""; for (int x=1; x= 1; x--) { int n = food[x] / 2; appendRepeated(answer, x, n); } return answer.toString(); } // 문자열에 숫자를 반복해서 추가하는 메소드 private void appendRepeated(StringBuilder sb, int x, int count) { for (int y = 0; y < count; y++) { sb.append(x); } } public static void main(String[] args) { int[] food ..
import java.util.*; class Solution { public int solution(int k, int m, int[] score) { int answer = 0; //정렬을 시키고... Arrays.sort(score); // 111/2233 //점수배열의 길이 - 상자 용량 //7-4=3, -1 for(int i = score.length - m; i >= 0; i -= m) /* (최저 사과 점수) x (한 상자에 담긴 사과 개수) x (상자의 개수) = 2 x 4 x 1 = 8 가 규칙이다. 2 * 4 가 들어가게 된다. 단순히 m개씩 끊어서 보는 셈이다. 정렬되어있는 전제하에 끊어서 최저 사과점수 값에 사과개수 m개를 차례차례 더하면 결과가 나온다. */ answer += sc..
import java.util.*; public class Solution { public static void main(String[] args) { // code(코드번호) date(제조일) maximum(최대 수량) remain(현재 수량) int[][] data = { {1, 20300104, 100, 80}, {2, 20300804, 847, 37}, {3, 20300401, 10, 8} }; // ( 어떤 정보를 기준으로 데이터를 뽑아낼지 ) String ext = "date"; // ( 뽑아낼 정보의 기준값을 나타내는 정수 ) // 제조일이 2030.05.01 이전인 것들을 int val_ext = 20300501; // ( 정보를 정렬할 기준이 되는 문자열 ) // 현재 수량이 적은 순서로..
public class Solution { public static void main(String[] args) { String[][] board = { {"blue", "red", "orange", "red"}, {"red", "red", "blue", "orange"}, {"blue", "orange", "red", "red"}, {"orange", "orange", "red", "blue"} }; int h = 1; int w = 1; /* h,w * 00 01 02 03 * 10 11 12 13 * 20 21 22 23 * 30 31 32 33 */ Solution sol = new Solution(); int result = sol.solution(board, h, w); System.out.p..
import java.util.*; public class Solution { public static void main(String[] args) { int[] bandage = {3, 2, 7}; int health = 20; int[][] attacks = {{1, 15}, {5, 16}, {8, 6}}; Solution sol = new Solution(); int result = sol.solution(bandage, health, attacks); System.out.println(result); } public int solution(int[] bandage, int health, int[][] attacks) { // 끝나는 시간 int endTime = attacks[attacks.len..
public class Solution { public static void main(String[] args) { int number = 5; // 기사단원의 수를 나타내는 정수 int limit = 3; // 공격력의 제한수치를 나타내는 정수 int power = 2; // 제한수치를 초과한 기사가 사용할 무기의 공격력을 나타내는 정수 Solution sol = new Solution(); int result = sol.solution(number, limit, power); System.out.println(result); } public int solution(int number, int limit, int power) { int answer = 0; int n = number; int[] div..