Skip to content

Commit

Permalink
이것이 취업을 위한 코딩테스트다 Ch04. 구현 - 왕실의 나이트
Browse files Browse the repository at this point in the history
  • Loading branch information
allrightDJ0108 committed Jul 13, 2023
1 parent 06a8ea6 commit c4cfe9d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Binary file added CodingTestStudy1.0/bin/ThisIsCT/ch04_03.class
Binary file not shown.
52 changes: 52 additions & 0 deletions CodingTestStudy1.0/src/ThisIsCT/ch04_03.java
@@ -0,0 +1,52 @@
package ThisIsCT;

import java.io.*;

public class ch04_03 {
// Ch.04 구현
// 왕실의 나이트

static int x, y;
static int[] dirX = {1, 1, -1, -1, 2, 2, -2, -2};
static int[] dirY = {2, -2, 2, -2, 1, -1, 1, -1};
static int result = 0;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split("");
String tempStr = str[0];
y = Integer.parseInt(str[1]);
if (tempStr.equals("a")) x = 1;
else if (tempStr.equals("b")) x = 2;
else if (tempStr.equals("c")) x = 3;
else if (tempStr.equals("d")) x = 4;
else if (tempStr.equals("e")) x = 5;
else if (tempStr.equals("f")) x = 6;
else if (tempStr.equals("g")) x = 7;
else if (tempStr.equals("h")) x = 8;

movingFn();
System.out.println(result);
}

/*
* 상 (2,1) (2,-1)
하 (-2,1) (-2,-1)
좌 (1,-2) (-1,-2)
우 (1,2) (-1,2)
* */

static void movingFn() {

for (int i=0; i<8; i++) {
int tempX = x + dirX[i];
int tempY = y + dirY[i];

if (tempX > 0 && tempX <= 8 && tempY > 0 && tempY <= 8) {
result++;
}
}


}
}

0 comments on commit c4cfe9d

Please sign in to comment.