|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 09:15 AM. |
| Sponsored Links |
|
|
|
|||||
|
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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||
|
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: Code:
srand(time(NULL));
int i,seed;
for(i = 0; i < rand() % 100; ++i)
{
seed = rand();
srand(seed);
}
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Goal: 100,000 Posts
Complete: 68%