Algorithm/SW Expert Academy
1284. 수도 요금 경쟁
히욤이
2019. 1. 24. 23:28
* 문제의 저작권은 SW Expert에 있습니다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import java.util.Scanner; public class Solution { static int answer; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int p; //A사 1리터당 P원 int q; //B사의 R리터 이하 요금 int r; //B사의 기준 int s; //B사의 R리터 초과시 1리터당 요금 int w; //종민이가 한달동안 사용하는 수도의 양 int T = sc.nextInt(); int b; int a = 0; for(int test_case = 1; test_case <= T; test_case++) { p = sc.nextInt(); q = sc.nextInt(); r = sc.nextInt(); s = sc.nextInt(); w = sc.nextInt(); a = (1*p*w); //A사의 한달동안 사용량 if (w<=r) { //종민이의 한달 사용량이 기본 요금보다 작으면 b = q; //b사 기준 가격은 q } else { //기본 요금보다 크면 b = q + ((w-r) * s); //기본요금 + 초과요금 } answer = (a<b?a:b); //작은 수 비교 System.out.println("#" + test_case +" " + answer ); } sc.close(); } } | cs |