1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
trapecia [35]
4 years ago
14

Your program should read from an input file, which will contain one or more test cases. Each test case consists of one line cont

aining 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.
Engineering
1 answer:
Aliun [14]4 years ago
3 0

Answer:

#include <bits/stdc++.h>

using namespace std;

struct cell

{

int x, y;

int dis;

cell() {}

cell(int x, int y, int dis) : x(x), y(y), dis(dis) {}

};

bool isInside(int x, int y, int N)

{

if (x >= 1 && x <= N && y >= 1 && y <= N)

return true;

return false;

}

int minStepToReachTarget(int knightPos[], int targetPos[],

int N)

{

int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2};

int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};

queue<cell> q;

q.push(cell(knightPos[0], knightPos[1], 0));

cell t;

int x, y;

bool visit[N + 1][N + 1];

for (int i = 1; i <= N; i++)

for (int j = 1; j <= N; j++)

visit[i][j] = false;

visit[knightPos[0]][knightPos[1]] = true;

while (!q.empty())

{

t = q.front();

q.pop();

visit[t.x][t.y] = true;

if (t.x == targetPos[0] && t.y == targetPos[1])

return t.dis;

for (int i = 0; i < 8; i++)

{

x = t.x + dx[i];

y = t.y + dy[i];

if (isInside(x, y, N) && !visit[x][y])

q.push(cell(x, y, t.dis + 1));

}

}

}

int main(){

ifstream obj("input.txt");

string line;

int x1,y1,x2,y2;

while(getline(obj,line)){

//cout<<line<<endl;

x1=line[0]-'a'+1;

y1=line[1]-'0';

x2=line[3]-'a'+1;

y2=line[4]-'0';

int N = 8;

int knightPos[] = {x1,y1};

int targetPos[] = {x2,y2};

cout <<"To get from "<<line[0]<<line[1]<<" to "<<line[3]<<line[4]<<" takes "<< minStepToReachTarget(knightPos, targetPos, N)<<" Knight Moves."<<endl;

}

return 0;

}

You might be interested in
A computer maintenance company wants to 'capture' the knowledge that employees carry around in their heads by creating a databas
galina1969 [7]

Answer: The answer is A. The company is trying to transfer intellectual capital to a knowledge management system

5 0
3 years ago
7. Sockets internal designs come in what sizes?
MAXImum [283]

Answer:

These drive fittings come in four common sizes: 1⁄4 inch, 3⁄8 inch, 1⁄2 inch, and 3⁄4 inch (referred to as "drives", as in "3⁄8 drive").

3 0
3 years ago
The mechanical advantage of a screw is always ____________________ than/to 1. Question 5 options: less, greater, equal, none of
torisob [31]

Answer:well u can use to make a shelter but that's all I can think of ??

Explanation:

3 0
3 years ago
Engineered lumber should not be used for
Dimas [21]

Answer:

Composite panel garage doors

Explanation:

8 0
2 years ago
Joey has a car that uses the hand crank to open the windows. Joey is wondering where the energy comes from to open the windows.T
Sedaia [141]

Explanation:

Joey has a car that uses the hand crank to open the windows. Joey is wondering where the energy comes from to open the windows.The sunHuman-powered energy from JoeyThe hand crankThe moving car

5 0
3 years ago
Other questions:
  • The rolling process is governed by the frictional force between the rollers and the workpiece. The frictional force at the entra
    5·1 answer
  • The controlled variable in a closed-loop system is the direction of a robot arm. Initially, it is at 50o; then it is commanded t
    12·1 answer
  • How did engineers help to create a ceiling fan
    8·1 answer
  • two cars travel on a straight road from the point. A to point B both cars accelerate to their maximum speed and then continue at
    10·1 answer
  • What learning is required to become a mechanical engineer?
    14·1 answer
  • A front wheel drive vehicle with four wheel disc brakes is pulling to the left. Tech A says an external kink or internal restric
    13·1 answer
  • What is the process pf distributing and selling clean fuel?​
    6·1 answer
  • When a company in the United States employs people in India to answer their customer service calls this is an example of
    9·1 answer
  • Technician A says that the starter solenoid switches the high current on and off. Technician B says that the solenoid on the sta
    5·1 answer
  • There are signs of oil spray on the compressor clutch hub and nearby underhood areas. Technician A says that a faulty compressor
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!