Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 스프링부트 도커로 배포
- 스프링부트 도커 배포
- 이진수 변환
- SWEA
- 백준
- Stack
- 알고리즘
- lv2
- 삼각형의 완성조건
- index of
- 프로그래머스
- 자바
- 백준 N과 M 자바
- 스프링부트 도커
- 큐
- Queue
- 스택
- StringTokenizer
- 오름차순 정렬
- lv0
- 프로그래머스 문자열 정렬
- 버퍼
- java
- Lv1
- 문자열
- 클라이언트
- 프로그래머스 자바
- Programmers
- 프로그래머스 풀이
- COS Pro
Archives
- Today
- Total
mun dev
[COS PRO 1급] 1-6 체스의 나이트 자바(Java) 본문
문제링크
구름HOME
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
www.goorm.io
문제유형
solution 함수 작성
문제
class Main{
public int solution(String pos) {
// 여기에 코드를 입력하세요.
int answer = 0;
return answer;
}
public static void main(String[] args) {
Main sol = new Main();
String pos = "A7";
int ret = sol.solution(pos);
System.out.println("solution 함수의 반환값은 " + ret + " 입니다.");
}
}
문제 풀이
class Main {
public static int dx[] = {2, 2, 1, -1, -2, -2, -1, 1};
public static int dy[] = {1, -1, 2, 2, -1, 1, -2, -2};
public static int map[][] = new int[8][8];
public int solution(String pos) {
int answer = 0;
int x = pos.charAt(0) - 'A';
int y = pos.charAt(1) - '0';
y--;
for (int i = 0; i < 8; i++) {
int cx = x + dx[i];
int cy = y + dy[i];
if (cx >= 0 && cy >= 0 && cx < 8 && cy < 8) {
answer++;
}
}
return answer;
}
public static void main(String[] args) {
Main sol = new Main();
String pos = "A7";
int ret = sol.solution(pos);
System.out.println("solution 함수의 반환값은 " + ret + " 입니다.");
}
}
'알고리즘 > COS PRO 1급' 카테고리의 다른 글
[COS PRO 1급] 1-8 누가 당선 되나요 자바(Java) (0) | 2023.11.25 |
---|---|
[COS PRO 1급] 1-7 병합 and 정렬 자바(Java) (0) | 2023.11.24 |
[COS PRO 1급] 1-5 소용돌이 수 자바(Java) (0) | 2023.11.24 |
[COS PRO 1급] 1-4 타임머신 자바(Java) (0) | 2023.11.24 |
[COS PRO 1급] 1-3계산기 by 문자열 자바(Java) (0) | 2023.11.24 |