Question: write the program in C++ Problem-2 A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the

write the program in C++write the program in C++ Problem-2 A friend of you is doing

Problem-2 A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour would be easy. Of course you know that it is vice versa. So you offer him to write a program that solves the "difficult" part. Your job is to write a program that takes two squares a and b as input and then determines the number of knight moves on a shortest route from a to b. Input The input file will contain one or more test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a..h) representing the column and a digit (1..8) representing the row on the chessboard. Output For each test case, print one line saying 'To get from xx to yy takes n knight moves.'. Sample Input Sample Output e2 e4 To get from e2 to e4 takes 2 knight moves. al b2 To get from al to b2 takes 4 knight moves. b2c3 To get from b2 to c3 takes 2 knight moves. al h8 To get from al to h8 takes 6 knight moves. al h7 To get from al to h7 takes 5 knight moves. h8 al To get from h8 to al takes 6 knight moves. bl c3 To get from bl to c3 takes 1 knight moves. f6 f6 To get from f6 to f6 takes O knight moves

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!