Write a program to input an H x W array of 0’s and 1’s where H and W are also user inputs.
You may assume that both H and W are non-zero and at most 10. The array represents an H
x W minefield so that a cell with a 1 (resp. 0) means the cell contains (does not contain) a
bomb. Your program should print the minefield as follows:
(1) If a cell contains a bomb, print a ‘#’.
(2) If a cell does not contain a bomb and is not adjacent to any bomb, print a ‘.’
(3) Otherwise, print the number of neighboring bombs.
Sample input and output (user input in boldface):
5 5
1 0 0 1 0
1 1 0 0 0
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
#32#1
##211
22111
...1#
...11
Last edited by wtxwt; 10-27-2007 at 07:15 AM.
You only need to store the latest guess and the code, which can be in strings. Then use some loops to work through the two strings using string functions.
I don't quite understand what you mean, can you explain it further?
Last edited by wtxwt; 10-24-2007 at 08:00 AM.
That little section of code appears after every single one of his posts. Its like his signature, so just ignore it. That confused me when I first started here too.
As for the unique random numbers...the rand() function generates pseudorandom numbers. If you seed it with the same number you'll get the same outputs. You did the right thing by seeding it with the time, but to make it even more random, try:
This will loop around a random number of times and keep reseeding the random number generator. Otherwise, your code looks great.Code:srand(time(NULL)); int i,seed; for(i = 0; i < rand() % 100; ++i) { seed = rand(); srand(seed); }
I still don't know how to start, pls give a hand to me
Last edited by wtxwt; 10-24-2007 at 08:01 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks