πλ¬Έμ μΆμ² : https://www.acmicpc.net/problem/3003
πcode μ μ₯μ :
hayannn/CodingTest_Java_NKLCBHub/#3003 νΉ,νΈ,룩,λΉμ,λμ΄νΈ,ν°v1
hayannn/CodingTest_Java_NKLCBHub/#3003 νΉ,νΈ,룩,λΉμ,λμ΄νΈ,ν°v2
ν°μ νΌμ€μ κ°μκ° μ£Όμ΄μ‘μ λ, λͺ κ°λ₯Ό λνκ±°λ λΉΌμΌ μ¬λ°λ₯Έ μΈνΈκ° λλμ§ κ΅¬νλ νλ‘κ·Έλ¨μ λλ€.
π¨ μ£Όμμ¬ν
- 쑰건
- μ λ ₯λ°μ μ«μλ 0λ³΄λ€ ν¬κ±°λ κ°κ³ 10λ³΄λ€ μκ±°λ κ°μ μ μμ λλ€.
π νμ΄ κ³Όμ λ° μ½λ
package baekjoon.level.L6;
import java.util.*;
public class BJ3003 {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int[] Pieces = new int[6]; //μ
λ ₯ν κ°μ
for(int i = 0; i<6; i++) {
Pieces[i] = scanner.nextInt();
}
int[] Chess = {1, 1, 2, 2, 2, 8}; //μ΄κΈ° κ°μ
int[] Result = new int[6]; //κ²°κ³Ό
for(int i = 0; i<6; i++) {
Result[i] = Chess[i] - Pieces[i]; // κ²°κ³Ό = μ΄κΈ° κ°μ - μ
λ ₯ν κ°μ
System.out.print(Result[i] + " ");
}
}
}
Result[i] = Chess[i] - Pieces[i];
π νμ΄ κ³Όμ λ° μ½λ
package baekjoon.level.L6;
import java.util.Scanner;
public class BJ3003v2 {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int king = 1;
int queen = 1;
int rook = 2;
int bishop = 2;
int knight = 2;
int pawn = 8;
king = king - scanner.nextInt();
queen = queen - scanner.nextInt();
rook = rook - scanner.nextInt();
bishop = bishop - scanner.nextInt();
knight = knight - scanner.nextInt();
pawn = pawn - scanner.nextInt();
System.out.print(king +" "+ queen +" " + rook+ " " + bishop + " " + knight + " " + pawn);
}
}
king = king - scanner.nextInt();
int[] νμ©
"μλμ νΌμ€ κ°μ - μ λ ₯λ°μ νΌμ€ κ°μ"λ‘ λ°λ‘ κ³μ°
β‘οΈ λ λ°©λ² λͺ¨λ λΉμ·ν κ²½μ°μ§λ§, μ
λ ₯ μμ λ°λ‘ λΉκ΅νλ κ²μΈμ§ μ
λ ₯μ λ°κ³ λ ν λΉκ΅νλ κ²μΈμ§ μ λμ μ°¨μ΄μ
λλ€.
μ΄ λ¬Έμ λ μμ scannerλ‘ νμ΄νκΈ° λλ¬Έμ BufferedReaderλ₯Ό μ΄μ©ν νμ΄λ νμν΄λ³΄μ
λλ€!
λͺ¨λ λ§μ μμμ κ°κ° μνλ μΌμ΄μ€μ μλ₯Ό ν΅μ§Έλ‘ λΉΌλ κ²½μ°
κ° λλ κ²μ΄μ£ .μμ
- μ λ ₯ : 0 1 2 2 2 7
-> kingμ 1κ°κ° λͺ¨μλλλ€.
-> queenμ 0κ°κ° λͺ¨μλλλ€.
-> rookμ 0κ°κ° λͺ¨μλλλ€.
...
package baekjoon.level.L6;
import java.util.*;
public class BJ3003 {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
String piece = scanner.nextLine();
//λ§ μ΄κΈ°ν
int king = 0;
int queen = 0;
int rook = 0;
int bishop = 0;
int knight = 0;
int pawn = 0;
for(int i = 0; i<11; i++){
switch (i) {
// λ§μ κ°μκ° λκ°μ κ²½μ°
case 0:
king = 1;
queen = 1;
rook = 2;
bishop = 2;
knight = 2;
pawn = 8;
break;
// λ§μ κ°μκ° 1κ° μ°¨μ΄ λλ κ²½μ°
case 1:
king = 0;
queen = 0;
rook = 1;
bishop = 1;
knight = 1;
pawn = 7;
break;
// λ§μ κ°μκ° 2κ° μ°¨μ΄ λλ κ²½μ°
case 2:
king = -1;
queen = -1;
rook = 0;
bishop = 0;
knight = 0;
pawn = 6;
break;
// λ§μ κ°μκ° 3κ° μ°¨μ΄ λλ κ²½μ°
case 3:
king = -2;
queen = -2;
rook = -1;
bishop = -1;
knight = -1;
pawn = 5;
break;
// λ§μ κ°μκ° 4κ° μ°¨μ΄ λλ κ²½μ°
case 4:
king = -3;
queen = -3;
rook = -2;
bishop = -2;
knight = -2;
pawn = 4;
break;
// λ§μ κ°μκ° 5κ° μ°¨μ΄ λλ κ²½μ°
case 5:
king = -4;
queen = -4;
rook = -3;
bishop = -3;
knight = -3;
pawn = 3;
break;
// λ§μ κ°μκ° 6κ° μ°¨μ΄ λλ κ²½μ°
case 6:
king = -5;
queen = -5;
rook = -4;
bishop = -4;
knight = -4;
pawn = 2;
break;
// λ§μ κ°μκ° 7κ° μ°¨μ΄ λλ κ²½μ°
case 7:
king = -6;
queen = -6;
rook = -5;
bishop = -5;
knight = -5;
pawn = 1;
break;
// λ§μ κ°μκ° 8κ° μ°¨μ΄ λλ κ²½μ°
case 8:
king = -7;
queen = -7;
rook = -6;
bishop = -6;
knight = -6;
pawn = 0;
break;
// λ§μ κ°μκ° 9κ° μ°¨μ΄ λλ κ²½μ°
case 9:
king = -8;
queen = -8;
rook = -7;
bishop = -7;
knight = -7;
pawn = -1;
break;
}
}
System.out.print(king +" "+ queen +" " + rook+ " " + bishop + " " + knight + " " + pawn);
}
}