[BaekJoon] #5565 - 영수증 [Java][C++]
[BaekJoon] #5565 - 영수증 [Java][C++]
1. 아이디어
10권의 가격 총합에서 9권의 가격을 빼면 남은 한 권의 가격을 구할 수 있다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int sum = Integer.parseInt(br.readLine());
for (int i = 1; i < 10; i++) {
sum -= Integer.parseInt(br.readLine());
}
System.out.println(sum);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int sum;
cin >> sum;
for (int i = 1; i < 10; i++) {
int x;
cin >> x;
sum -= x;
}
cout << sum;
}
This post is licensed under CC BY 4.0 by the author.