FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-for-coding-test/4/3.java at master · ndb796/python-for-coding-test · GitHub
ndb796
/
python-for-coding-test
Public
Notifications
You must be signed in to change notification settings
Fork
831
Star
2.4k
Code
Issues
129
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-for-coding-test
/
4
/
3.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (25 loc) · 1.01 KB
Breadcrumbs
python-for-coding-test
/
4
/
3.java
Copy path
File metadata and controls
32 lines (25 loc) · 1.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
import
java
.
util
.*;
public
class
Main
{
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
// 현재 나이트의 위치 입력받기
String
inputData
=
sc
.
nextLine
();
int
row
=
inputData
.
charAt
(
1
) -
'0'
;
int
column
=
inputData
.
charAt
(
0
) -
'a'
+
1
;
// 나이트가 이동할 수 있는 8가지 방향 정의
int
[]
dx
= {-
2
, -
1
,
1
,
2
,
2
,
1
, -
1
, -
2
};
int
[]
dy
= {-
1
, -
2
, -
2
, -
1
,
1
,
2
,
2
,
1
};
// 8가지 방향에 대하여 각 위치로 이동이 가능한지 확인
int
result
=
0
;
for
(
int
i
=
0
;
i
<
8
;
i
++) {
// 이동하고자 하는 위치 확인
int
nextRow
=
row
+
dx
[
i
];
int
nextColumn
=
column
+
dy
[
i
];
// 해당 위치로 이동이 가능하다면 카운트 증가
if
(
nextRow
>=
1
&&
nextRow
<=
8
&&
nextColumn
>=
1
&&
nextColumn
<=
8
) {
result
+=
1
;
}
}
System
.
out
.
println
(
result
);
}
}
Back
|
FazBrowse Home
|
New Git URL