package com.backjun.algorithm;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int hambergLowPrice=0;
int beverageLowPrice=0;
for (int i=0; i<5; i++){
int price = Integer.parseInt(br.readLine());
if(i==0){
hambergLowPrice = price;
} else if (i<3) {
hambergLowPrice = price < hambergLowPrice ? price : hambergLowPrice;
} else if (i==3) {
beverageLowPrice = price;
} else if (i<5) {
beverageLowPrice = price < beverageLowPrice ? price : beverageLowPrice;
}
}
System.out.println(hambergLowPrice + beverageLowPrice - 50);
}
}
Math.min을 사용하면 아래처럼.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int min(int a, int b){
return a<b ? a:b;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print(min(Integer.parseInt(br.readLine()), min(Integer.parseInt(br.readLine()),
Integer.parseInt(br.readLine()))) + min(Integer.parseInt(br.readLine()),
Integer.parseInt(br.readLine())) - 50);
}
}
min을 함수로 정의해서 사용.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int min(int a, int b){
return a<b ? a:b;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print(min(Integer.parseInt(br.readLine()), min(Integer.parseInt(br.readLine()),
Integer.parseInt(br.readLine()))) + min(Integer.parseInt(br.readLine()),
Integer.parseInt(br.readLine())) - 50);
}
}
'알고리즘 > acmicpc.net' 카테고리의 다른 글
#10039 (0) | 2020.07.13 |
---|---|
1110 (0) | 2020.07.10 |
10951&10952 (0) | 2020.07.10 |
10871 (0) | 2020.07.08 |
2439 (0) | 2020.07.08 |