#include #include #include #include #include using namespace std; int d[8][8]; int main() { string a,b; while (cin >> a >> b) { int x1=a[0]-'a', y1=a[1]-'1'; int x2=b[0]-'a', y2=b[1]-'1'; for (int y=0;y<8;y++) for (int x=0;x<8;x++) d[y][x]=-1; d[y1][x1]=0; queue > q; q.push({y1,x1}); while (!q.empty()) { int y=q.front().first, x=q.front().second; q.pop(); if (y==y2 && x==x2) break; for (int dx=-2;dx<=2;dx++) { for (int dy=-2;dy<=2;dy++) { if (abs(dx)+abs(dy)==3) { int yy=y+dy, xx=x+dx; if (0<=yy && yy<8 && 0<=xx && xx<8) { if (d[yy][xx]==-1) { d[yy][xx]=d[y][x]+1; q.push({yy,xx}); } } } } } } cout << "To get from " << a << " to " << b << " takes " << d[y2][x2] << " knight moves." << endl; } return 0; }