Post

[BaekJoon] 2845번 - 파티가 끝나고 난 뒤 [Java][C++]

[BaekJoon] 2845번 - 파티가 끝나고 난 뒤 [Java][C++]

문제 링크


1. 문제 풀이


$1m^2$ 당 $L$ 명의 사람이 있고 넓이가 $P$ 이므로 전체 사람의 수는 $L \times P$ 이다. 기사의 참가자 수에서 해당 값을 빼면 차이를 구할 수 있다.


2. 코드


1. 풀이 [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
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(br.readLine());

        int L = Integer.parseInt(st.nextToken());
        int P = Integer.parseInt(st.nextToken());

        int[] arr = new int[5];
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < 5; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }

        for (int n : arr) {
            sb.append(n - L * P).append(" ");
        }

        System.out.println(sb);
    }
}


2. 풀이 [C++]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int l, p;
    cin >> l >> p;

    vector<int> v(5);
    for (int& x : v) cin >> x;

    for (int x : v) {
        cout << x - l * p << ' ';
    }
}

This post is licensed under CC BY 4.0 by the author.