[C++]Code for outputting maze

Hi, I'm in final year of High School and IT university I want to study (the best one in my country) has made a programming tasks, and whoever will complete them, is accepted, so I'll be probably posting here a few tasks so you can learn with me and I'll also ask you for help.



The first task is, the shortest path from the start to the end of maze has exact length. Start is at the upper left-hand corner and end is at the bottom right-hand corner. You can move only on neighbourhood square that shares with your actual square full side.



Let's call the moving object warden. You have to make maze for every warden.



Input explanation:

In the first line is one integer 1<= t <= 1000. t........number of wardens

Then follows t lines (that means one maze for each warden)

Each line contains 3 integers m, n, k.

1<=m<=75

1<=n<=75

n+m-1<=k<=2*(((m-1)/4)*((n-1)mod 4)+((n-1)/4)*(m-1))+m+n-1

m, n.......dimensions of maze for the warden

k......exact lenght of the shortest path from start to the end



Output explanation:

For each of wardens output m lines containing n characters, where each character is a wall (#) or free square (.). If there are more solutions, choose any ONE of them. If its impossible to create maze from given inputs, output for that warden on one line "Impossible".



(this means that m are lines, n are columns)



Examples:

https://snag.gy/qfYL7o.jpg

https://snag.gy/2FDkf3.jpg



I have written only requests for dimensions of each warden, now I think Im done ;(



My code:

#include <iostream>

#include <math.h>



using namespace std;



int main()

{

int t, m, n, k, nk, vk;

cout << "Zadejte pocet dozorcu (od 1 do 1000)" << endl; // INPUT NUMBER OF WARDENS

cin >> t;

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

{

nk=0;

vk=0;

cout << "Rozmery oblasti " << i << ". dozorce:" << endl; // DIMENSONS OF MAZE OF i WARDEN

cout << "Zadejte m (od 1 do 75)(pocet radku)" << endl; // INPUT M

cin >> m;

cout << "Zadejte n (od 1 do 75)(pocet sloupcu)" << endl; // INPUT N

cin >> n;

nk=n+m-1;

vk=2*(((m-1)/4)*((n-1)%4)+((n-1)/4)*(m-1))+m+n-1; // k

cout << "Zadejte k (od " << nk << " do " << vk << ") (vzdalenost)" << endl; // INPUT K

cin >> k;

}



return 0;

}
Last edited on
> and whoever will complete them, is accepted
So if we help you to get in, will you need continuing help to keep you in?

Your main should be something like this. Study your output, there is no trace of UI prompts.
1
2
3
4
5
cin >> t;
for ( int i = 1 ; i <= t ; i++ ) {
  cin >> m >> n >> k;
  calculateMaze(m,n,k);
}


When you get to submit your program to the automated checker, it will be run like so
1
2
3
g++ -o prog.exe prog.cpp
./prog.exe < input.txt >output.txt
diff output.txt correct.txt

That is
- compile your program
- run the program with input taken from input.txt and the results written to output.txt
- perform a text difference between your output and the expected output.

If there is any difference at all (like your flowery prompting), you will fail.
Topic archived. No new replies allowed.