[BaekJoon] #3003 - 킹, 퀸, 룩, 비숍, 나이트, 폰 [Java][C++]
[BaekJoon] #3003 - 킹, 퀸, 룩, 비숍, 나이트, 폰 [Java][C++]
1. 아이디어
체스에서 필요한 각 피스의 수에서 입력으로 주어진 피스들의 수를 빼면 더하거나 빼야 되는 피스의 수를 구할 수 있다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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));
StringTokenizer st = new StringTokenizer(br.readLine());
int[] arr = {1, 1, 2, 2, 2, 8};
for (int n : arr) {
int x = Integer.parseInt(st.nextToken());
System.out.print((n - x) + " ");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;
int arr[6] = {1, 1, 2, 2, 2, 8};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int n : arr) {
int x;
cin >> x;
cout << n - x << ' ';
}
}
This post is licensed under CC BY 4.0 by the author.