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:
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.
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();
}
}
}
결과는
풀었다.
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
}
}