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
HELP!
olya-2409 [2.1K]
The thickness is thick
5 0
3 years ago
In order to protect yourself if you have a dispute with another drivers insurance company you should:
klio [65]

Answer:

  C. Get the names and addresses of witness to the crash

Explanation:

The best approach is to let your insurance company handle the dispute. Since that is not an option here, the best thing you can do is make sure you know who the witnesses are, so your insurance company can call upon them as needed.

8 0
3 years ago
The speed of sound in a fluid can be calculated using the following equation:
wlad13 [49]

Answer:

Jesus is always the answer

4 0
3 years ago
Cite the phases that are present and the phase compositions for the following alloys: (a) 15 wt% Sn - 85 wt% Pb at 100 o C. (b)
Novosadov [1.4K]

Answer:

a)  ∝  and β

   The phase compositions are :

    C_{\alpha } = 5wt% Sn - 95 wt% Pb

    C_{\beta } =  98 wt% Sn - 2wt% Pb

b)

The phase is; ∝  

The phase compositions is;   82 wt% Sn - 91.8 wt% Pb

Explanation:

a) 15 wt% Sn - 85 wt% Pb at 100⁰C.

The phases are ; ∝  and β

The phase compositions are :

C_{\alpha } = 5wt% Sn - 95 wt% Pb

C_{\beta } =  98 wt% Sn - 2wt% Pb

b) 1.25 kg of Sn and 14 kg Pb at 200⁰C

The phase is ; ∝  

The phase compositions is;  82 wt% Sn - 91.8 wt% Pb

Csn = 1.25 * 100 / 1.25 + 14 = 8.2 wt%

Cpb = 14 * 100 / 1.25 + 14 = 91.8 wt%

6 0
3 years ago
PLZZ HELP
9966 [12]

Answer:

Could ask a family member to help

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • Please read
    6·1 answer
  • Define initial set and final set. Briefly discuss one method used to determine them. The following laboratory tests are performe
    12·1 answer
  • 1. True or False: When two batteries are wired in Series the Volts go up and the Amp Hours stay the same. 2. True or False: When
    6·1 answer
  • Question 64 (1 point)
    9·1 answer
  • 9.21 A household oven door of 0.5-m height and 0.7-m width reaches an average surface temperature of 32℃ during operation. Estim
    8·1 answer
  • while performing a running compression test how should running compression compare to static compression
    5·1 answer
  • Everyone has only one learning style. True or false? hurry pleasle this exp carees class
    11·1 answer
  • A hub a signal that refreshes the signal strength.
    5·1 answer
  • Technician A says that fuel filler caps with pressure and vacuum vents are used with EVAP system fuel tanks. Technician B says t
    5·1 answer
  • You may wonder who the rest goes
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!