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