백준 5543번(상근날드) 문제풀이

YeonghooAhn·2021년 10월 28일
0

알고리즘

목록 보기
2/5

import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int sang = sc.nextInt();
        int jung = sc.nextInt();
        int ha = sc.nextInt();
        int col = sc.nextInt();
        int sa = sc.nextInt();
        int result1 = Math.min(sang + col - 50, sang + sa - 50);
        int result2 = Math.min(jung + col - 50, jung + sa - 50);
        int result3 = Math.min(ha + col - 50, ha + sa - 50);
        int result;
        if (result1 < result2 && result1 < result3) result = result1;
        else if (result2 < result1 && result2 < result3) result = result2;
        else result = result3;
        System.out.println(result);

    }
}

무지성 하드코딩 했습니다.

햄버거 종류 3개와 콜라 2개 가격 값을 입력받고

각 세트별로 가격값을 비교하면 세 개의 경우가 나옵니다.

이 세 개의 경우를 result1,2,3 변수에 담아주고

최종 결과는 result 변수에 담아주기 위해 미리 선언해주고

if~elseif~else문으로 result에 가장 작은값을

담아줍니다. 사실 더 짧고 간단하게 풀 수 있을 것 같은데

이 문제는 생각하기 싫어서 그냥 무지성으로 풀었습니다..

profile
책 중독 컴공과

0개의 댓글