Guest User

Untitled

a guest
Nov 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. >> matrix = [1 2 3;4 5 6;7 8 9;10 11 1]
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. string imatrix;
  12. int n = 0;
  13.  
  14. cout<<"Matrix: ";
  15. getline(cin,imatrix);
  16.  
  17. const int dim = imatrix.length();
  18. char im[dim];
  19.  
  20. for(int i=0; i<dim; i++)
  21. im[i]=imatrix.at(i);
  22.  
  23. int rows = 1;
  24. int col = 0;
  25.  
  26. for(int j=0; j<dim; j++)
  27. {
  28. if(im[j] == ';')
  29. rows += 1;
  30. if(im[j] != '[' && im[j] != ' ' && rows == 1 )
  31. col += 1;
  32. }
  33.  
  34. int matrix[rows][col];
  35. int strip[rows*col];
  36. int temp;
  37.  
  38. /*
  39. This is the part were I am stuck. I need to somehow create the strip
  40. array.
  41.  
  42. I tried this:
  43.  
  44. for(int m = 0; m<dim; i++)
  45. {
  46. if(im[m]=='[' || im[m] == ' ' || im[m] == ';')
  47. continue;
  48. else
  49. {
  50. temp = im[m]; //temporarily save the digit just found
  51.  
  52. //Checking if there are numbers on positions after the one found
  53. for(int t = m; t<dim, t++)
  54. {
  55. if(im[t]!='[' && im[m] != ' ' || im[t] != ';')
  56. {
  57. //save the digits found
  58.  
  59. }
  60. else
  61. {
  62. //save temp followed by the digits found, into position (i) in the array strip.
  63. index = t;
  64. break;
  65. }
  66. }
  67.  
  68. }
  69. m = index; // make the loop begin from m
  70. }
  71.  
  72.  
  73. */
  74.  
  75.  
  76. for(int k=0; k<rows; k++)
  77. {
  78. for(int s=0; s<col; s++)
  79. {
  80.  
  81. matrix[k][s] = strip[n];
  82. n += 1;
  83. }
  84. }
  85.  
  86. system("PAUSE");
  87. }
Add Comment
Please, Sign In to add comment