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
What is the following passage saying about the relationship between sustainability and responsibility?
7nadin3 [17]

What the given passage is saying about the relationship between sustainability and responsibility is that;

C: We should only consider products or services to be green if their broad impact can be considered so.

<h3>Sustainability</h3>

From the passage, we see a write up questioning if the things we term to be green are truly green.

Now, from the passage, we see that a biofuel that is considered to be green is not really green if we consider that if it requires massive overproduction, it could wreck the water table.

Also, he says that if the production is local but also wasteful then it is not green.

Thus, we can see clearly that before we term a product or service as green, we should also consider their broad impact on the environment.

Read more about sustainability at; brainly.com/question/14154063

7 0
2 years ago
Explain by Research how a basic generator works ? using diagram<br>​
natulia [17]
Correcto no se muy bien de que se trata el tema porque está en inglés.
Sorry
8 0
2 years ago
An L2 steel strap having a thickness of 0.125 in. and a width of 2 in. is bent into a circular arc of radius 600 in. Determine t
lesya692 [45]

Answer:

the maximum bending stress in the strap is 3.02 ksi

Explanation:

Given the data in the question;

steel strap thickness = 0.125 in

width = 2 in

circular arc radius = 600 in

we know that, standard value of modulus of elasticity of L2 steel is; E = 29 × 10³ ksi;

Now, using simple theory of bending

1/p = M/EI

solve for M

Mp = EI

M = EI / p ----- let this be equation 1

The maximum bending stress in the strap is;

σ = Mc / I -------let this be equation 2

substitute equation 1 into 2

σ = ( EI / p)c / I

σ = ( c/p )E

so we substitute in our values

σ = ( (0.125/2) / 600 )29 × 10³

σ = 0.00010416666 × 29 × 10³

σ = 3.02 ksi

Therefore, the maximum bending stress in the strap is 3.02 ksi

3 0
3 years ago
Only answer this if your name is riley
Sati [7]

Answer:

hey im like kinda riley

Explanation:

y u wanna talk to moi

3 0
3 years ago
Read 2 more answers
Which of the following is typically wom when working in an atmosphere containing dust?
alukav5142 [94]

Answer:

Either D or C

Both of these masks are used for dust, but since half masks are generally cheaper and easier to use, I'd go with C.

If this is correct, I'd appreciate a brainliest.

3 0
2 years ago
Other questions:
  • What are supercapacitors ?
    13·2 answers
  • Write a single statement that prints outsideTemperature with 2 digits in the fraction
    8·1 answer
  • A poundal is the force required to accelerate a mass of 1 lbm at a rate of 1 ft/(s^2). Determine the acceleration of an object o
    10·1 answer
  • Explain the differences among sand, silt, and clay, both in their physical characteristics and their behavior in relation to bui
    15·1 answer
  • In this type of projection, the angles between the three axes are different:- A) Isometric B) Axonometric C) Trimetric D) Dimetn
    11·1 answer
  • 2. A well of 0.1 m radius is installed in the aquifer of the preceding exercise and is pumped at a rate averaging 80 liter/min.
    14·1 answer
  • Which of the following is true Select one: a. HTML stands for Hyper Text Markup Language is a language for describing web pages
    6·1 answer
  • Is an ideal way for a high school student to see what an engineer does on a typical day but does not provide a hands-on experien
    9·2 answers
  • Please help, Artificial Intelligence class test
    12·1 answer
  • Hello, I have a question, I would be glad if you can help.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!