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]
3 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]3 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
True or false <br> 19. Closed systems rely on feedback from outside of the system to operate.
Furkat [3]

Answer: True

Explanation: Closed loop relies on feedback from PNS to make modifications in the movement, open loop allows action in the absence of feedback, 2. ... Closed loop can change the initial commands, open loop can not change the initial commands.

6 0
3 years ago
Dampness or moisture introduces ____ into the weld, which causes cracking when some metals are welded.
N76 [4]

Answer: Dampness or moisture introduces hydrogen into the weld, which causes cracking when some metals are welded.

Explanation:

<em>This moisture (hydrogen) is a major cause of weld cracking and porosity. </em>

5 0
2 years ago
A friend would like you to build an "electronic eye" for use as a fake security device. The device consists of three lights line
mars1129 [50]

Answer and explanation:

The graphical representation of the electronic eye

The state table showing

the present state

input

Next state and

the output

are shown in the attached file

8 0
3 years ago
Read 2 more answers
The input and output signals of a system is related by the following equation: fraction numerator d squared y over denominator d
Colt1911 [192]

Answer:

Explanation:

The given equation is :

\frac{d^{2}y }{dx^{2} } + sin(3y) \frac{dy}{dt} + y = t\frac{df}{dt} + f

5 0
3 years ago
Gtjffs
grandymaker [24]

the required documents is 3000

4 0
3 years ago
Other questions:
  • A device is needed to accelerate a 3000 lb vehicle into a barrier with constant velocity to test its 5 mph bumpers. The vehicle
    12·2 answers
  • To make 1000 containers of ice cream you need: 600 gallons of milk, 275 gallons of cream, and 120 gallons of flavor. Each ingred
    12·1 answer
  • A strip of AISI 304 stainless steel, 2mm thick by 3cm wide, at 550°C, continuously enters a cooling chamber that removes heat at
    12·1 answer
  • In order to build a skyscraper Builders, Inc. hires 400 construction workers and 50 managers. Builders, Inc. represents A entrep
    8·1 answer
  • An FCC iron-carbon alloy initially containing 0.20 wt% C is carburized at an elevated temperature and in an atmosphere wherein t
    6·1 answer
  • A hot-water stream at 80°C enters a mixing chamber with a mass flow rate of 0.46 kg/s where it is mixed with a stream of cold wa
    14·1 answer
  • List everything wrong with 2020
    5·2 answers
  • Technician A says that in a worm gear steering system, most excessive steering free play is usually found in the gearbox. Techni
    13·1 answer
  • A life cycle assessment (LCA) determines the environmental impact at all stages of a product's life cycle, including production,
    12·1 answer
  • What factors need to be considered when building housing on a waterway
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!