문제: https://www.acmicpc.net/problem/9325
문제를 잘 읽고 요구사항대로 구현하면 되는 문제입니다.
소스 코드를 참고하세요.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int numOfTestCases = scanner.nextInt(); for (int i = 0; i < numOfTestCases; ++i) { int priceOfCar = scanner.nextInt(); int numOfDifferentOptions = scanner.nextInt(); int totalPrice = priceOfCar; for (int j = 0; j < numOfDifferentOptions; ++j) { int numOfOptions = scanner.nextInt(); int priceOfOption = scanner.nextInt(); totalPrice += numOfOptions * priceOfOption; } System.out.println(totalPrice); } scanner.close(); } } | cs |
소스 코드