I have a problem with Input and Output in my program.
I can’t make sure that the BFS response for each horse is separated and at the end the BFS response of all horses of a given number of examples is summarized.
Everything works well for this example:
- 1- number of examples
- 1 - the number of chess knights
- 5 5 - the starting point
- 5 6 - the final point
answer: 3
but not this example:
- 1- number of examples
- 2 - the number of chess knights
- 0 0 - the starting point of the first knight
- 1 0 - the starting point of the second knight
- 0 1 - the final point of the first knight
- 1 1 - the final point of the second knight
I need the answer(BFS) for the first horse and for the second horse to be summed up (for first = 2, for second = 2, for all horses = 4). But if you check this example using my code (below) then the answer is 3, the program considers only the first horse.
Here is my code:
int main()
{
int number_of_examples;
cin >> number_of_examples; //number of examples
for (int i = 1; i <= number_of_examples; i++) {
int number_of_horse;
cin >> number_of_horse; //number of horse
vector<Node> src;
vector<Node> dest;
int x, y;
for (int i = 1; i <= number_of_horse; i++)
cin >> x >> y;
src.push_back(Node(x, y));
for (int i = 1; i <= number_of_horse; i++)
cin >> x >> y;
dest.push_back(Node(x, y));
for (int i = 0; i < src.size(); i++)
{
for (int j = 0; j < dest.size(); j++)
{
cout << BFS(src[i], dest[j]);
}
}
}
return 0;
}