You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

#include <bits/stdc++.h>
using namespace std;
const int N = 10;
char g[N][N];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int x1, y1, x2, y2;
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++) {
cin >> g[i][j];
if (g[i][j] == 'C') x1 = i, y1 = j;
if (g[i][j] == 'F') x2 = i, y2 = j;
}
int cd = 0, fd = 0;
int cnt = 0;
while (true) {
int tx = x1 + dx[cd], ty = y1 + dy[cd];
if (tx >= 10 || tx < 0 || ty >= 10
|| ty < 0 || g[tx][ty] == '*')
cd = (cd + 1) % 4;
else
x1 = tx, y1 = ty;
tx = x2 + dx[fd], ty = y2 + dy[fd];
if (tx >= 10 || tx < 0 || ty >= 10 || ty < 0 || g[tx][ty] == '*')
fd = (fd + 1) % 4;
else
x2 = tx, y2 = ty;
cnt++;
if (x1 == x2 && y1 == y2) {
cout << cnt << endl;
break;
}
if (cnt > 10000) {
cout << 0 << endl;
break;
}
}
return 0;
}