Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> matrix = [1 2 3;4 5 6;7 8 9;10 11 1]
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- int main()
- {
- string imatrix;
- int n = 0;
- cout<<"Matrix: ";
- getline(cin,imatrix);
- const int dim = imatrix.length();
- char im[dim];
- for(int i=0; i<dim; i++)
- im[i]=imatrix.at(i);
- int rows = 1;
- int col = 0;
- for(int j=0; j<dim; j++)
- {
- if(im[j] == ';')
- rows += 1;
- if(im[j] != '[' && im[j] != ' ' && rows == 1 )
- col += 1;
- }
- int matrix[rows][col];
- int strip[rows*col];
- int temp;
- /*
- This is the part were I am stuck. I need to somehow create the strip
- array.
- I tried this:
- for(int m = 0; m<dim; i++)
- {
- if(im[m]=='[' || im[m] == ' ' || im[m] == ';')
- continue;
- else
- {
- temp = im[m]; //temporarily save the digit just found
- //Checking if there are numbers on positions after the one found
- for(int t = m; t<dim, t++)
- {
- if(im[t]!='[' && im[m] != ' ' || im[t] != ';')
- {
- //save the digits found
- }
- else
- {
- //save temp followed by the digits found, into position (i) in the array strip.
- index = t;
- break;
- }
- }
- }
- m = index; // make the loop begin from m
- }
- */
- for(int k=0; k<rows; k++)
- {
- for(int s=0; s<col; s++)
- {
- matrix[k][s] = strip[n];
- n += 1;
- }
- }
- system("PAUSE");
- }
Add Comment
Please, Sign In to add comment