Matrix with dynamic columns?

Asked

Viewed 67 times

1

I have a matrix like this: int numeros[qNum][6];

In reality it stores an integer number per line, separating the digits, for example:

I have the number 1234, in the matrix will be: numeros[0][0] = 1; numeros[0][1] = 2;

And so on and so forth. However, I have numbers composed of 4, 5 and 6 digits, as I do to define the matrix with dynamic columns, because this way the line 0 is not being 1234 but 123400. That is, it is always having 6 columns, filling the number I want and completing the rest of the columns with 0. How do I not do this, example have an array with the rows:

1234 14086 815108 No zeroes to mess with?

1 answer

0


Put zeroes on the left

// 1234
numeros[0][0] = 0; numeros[0][1] = 0; numeros[0][2] = 1;
      numeros[0][3] = 2; numeros[0][4] = 3; numeros[0][5] = 4;

// 14086
numeros[1][0] = 0; numeros[1][1] = 1; numeros[1][2] = 4;
      numeros[1][3] = 0; numeros[1][4] = 8; numeros[1][5] = 6;

// 815108
numeros[2][0] = 8; numeros[2][1] = 1; numeros[2][2] = 5;
      numeros[2][3] = 1; numeros[2][4] = 0; numeros[2][5] = 8;
  • In this case 0 to the left is also worth something. Because in reality it is a game of hunting numbers (college work) so I’m putting these numbers in a matrix to then allocate them randomly in another matrix to generate the game board

  • There is how I read an integer vector and store each digit typed in a position of it?

  • You can experiment with a different value to mean empty position, for example, -1: numeros[0][0] = 1; numeros[0][1] = 2; numeros[0][2] = 3; numeros[0][3] = 4; numeros[0][4] = -1; numeros[0][5] = -1;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.