hello.. i need tips to solve the problem. The situation is like this:
I have randomly generated 20 (pop) array of length = board. The output is this:
1 3 6 4 1 4 6 6
2 0 1 1 1 3 1 3
3 6 3 4 7 4 6 1
4 6 5 4 6 7 7 6
3 2 5 0 3 3 3 6
7 3 2 5 1 0 5 7
5 4 3 4 6 5 5 3
3 5 1 2 4 3 6 2
0 2 0 6 0 0 6 5
2 1 2 6 6 5 1 4
5 7 4 2 4 0 6 0
3 4 0 7 2 3 1 2
6 2 1 5 1 3 7 2
0 2 1 2 1 2 5 1
4 0 6 5 1 5 1 0
2 2 1 4 3 7 7 6
7 4 6 6 5 4 6 6
3 7 7 1 1 7 1 7
1 5 1 6 5 4 6 2
2 6 5 0 4 7 2 7
I also have created an area matrix (of size board x board) with initial value=0.
Next:
I want to fill the area matrix with value=1, but the position of the value is according to the number generated earlier, first row only. Means that...for
1 3 6 4 1 4 6 6
each column will be the position of value=1 for each row in the area matrix, so that the output will be like this:
0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 1 0
Can someone give me any HINTS?
The code is shown below:
#include <iostream>
#include <stdlib.h>
int main()
{
const board=8;
const pop=20;
using std::cout;
using std::endl;
int table [30][1000];
int area[board][board];
int r;
int c;
// Initialize random number generator.
for(r=0; r<=pop-1; r++)//row
{
for(c=0; c<board; c++)
{
table[r][c] = rand()%board;
}
}
for(r=0; r<=pop-1; r++)//row
{
cout << endl;
for(c=0; c<board; c++)
{
cout << "\t" << table[r][c]; // print out the numbers
}
cout << endl ;
}
system("pause");
cout << "\n";
// intialize the area matrix equal to 0
for(r=0; r<board; r++)
{
for(c=0; c<board; c++)
{
area[r][c]=0;
cout << "\t" << area[r][c];
}
cout << endl << endl;
}