8370번 : Plane

상환·2021년 12월 6일
0
post-thumbnail

문제

Byteland Airlines recently extended their aircraft fleet with a new model of a plane. The new acquisition has n1 rows of seats in the business class and n2 rows in the economic class. In the business class each row contains k1 seats, while each row in the economic class has k2 seats.

Write a program which:

  • reads information about available seats in the plane,
  • caulates the sum of all seats available in that plane,
  • writes the result.

입출력

1. 입력

In the first and only line of the standard input there are four integers n1, k1, n2 and k2 (1 ≤ n1, k1, n2, k2 ≤ 1 000), separated by single spaces.

2. 출력

The first and only line of the standard output should contain one integer - the total number of seats available in the plane.

풀이

해석하면

비행기를 새로 만들었다. 새 비행기는 비즈니스석 n1줄, 이코노미 n2줄이 있고 비즈니스 시트수는 k1개, 이코노미는 k2개가 있다. 총 좌석수를 출력해라.

이다. 입력 순서가 n1, k1, n2, k2이므로 n1 * k1 + n2 * k2해주면 된다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int[] seats = Arrays
            	.stream(br.readLine().split(" "))
                .mapToInt(Integer::parseInt)
                .toArray();
            br.close();
            System.out.println(seats[0]*seats[1]+seats[2]*seats[3]);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

결과는

풀었다.

kotlin code

import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    try {
        var seats = br.readLine().split(" ").map(String::toInt)
        br.close()
        print(seats[0] * seats[1] + seats[2] * seats[3])
    } catch (e: IOException) {
        e.stackTrace
    }
}
profile
레모네이드 커피

0개의 댓글