반응형
문제 (링크)
문제 설명
어렵지 않게 문제에 나온 식만 따라하면 되는 문제다.
반올림을 쓸 때는 Math.round(반올림할 값)을 쓰면 된다.
1
|
scan.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
|
cs |
답에서 위와 같이 scan.skip이 써있는 이유는 여러줄을 입력받을 때 공백의 엔터값을 스킵하기 위해서다.
답 (Java)
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
37
|
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
// Complete the solve function below.
static void solve(double meal_cost, int tip_percent, int tax_percent) {
double tip = meal_cost * tip_percent / 100;
double tax = meal_cost * tax_percent / 100;
double total_cost = meal_cost + tip + tax;
System.out.print(Math.round(total_cost));
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
double meal_cost = scanner.nextDouble();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
int tip_percent = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
int tax_percent = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
solve(meal_cost, tip_percent, tax_percent);
scanner.close();
}
}
|
cs |
반응형