-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3041.cpp
57 lines (52 loc) · 1.03 KB
/
3041.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 3041. N-퍼즐
// 2020.09.12
// 구현
#include<iostream>
#include<string>
using namespace std;
char map[4][4];
char origin[4][4];
int main()
{
string s;
int cnt = 0;
for (int i = 0; i < 4; i++)
{
cin >> s;
for (int j = 0; j < 4; j++)
{
map[cnt][j] = s[j];
}
cnt++;
}
// 완성본을 미리 만들어줌
cnt = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
origin[i][j] = cnt + 'A';
cnt++;
}
}
// 입력값과 완성본을 비교함
int ans = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
for (int k = 0; k < 4; k++)
{
for (int l = 0; l < 4; l++)
{
if (origin[i][j] == map[k][l])
{
ans += abs(i - k) + abs(j - l);
}
}
}
}
}
cout << ans << endl;
return 0;
}