Advertisement
Guest User

stergereLinie

a guest
May 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void print(const vector<vector<int>> &mat);
  7.  
  8. int main()
  9. {
  10. vector<vector<int>> mat;
  11. mat.resize(10);
  12. for (int i = 0; i < mat.size(); ++i)
  13. mat[i].resize(10);
  14.  
  15. for (int i = 0; i < mat.size(); ++i)
  16. {
  17. for (int j = 0; j < mat[i].size(); ++j)
  18. {
  19. mat[i][j] = mat.size() * i + j + 1;
  20. }
  21. }
  22. // Here you can work with the "Matrix" (actually a multi-dimensional vector)
  23. //..
  24. //..
  25. //..
  26. // Print it for example
  27. cout << "print the original matrix:" << endl;
  28. print(mat);
  29.  
  30. // Now I beleive, you want to delete a row
  31. mat.erase(mat.begin() + 1);
  32.  
  33. // And now you can print it again
  34. cout << "print the matrix after we have deleted the second row" << endl;
  35. print(mat);
  36.  
  37. return 0;
  38. }
  39.  
  40. void print(const vector<vector<int> > &mat)
  41. {
  42. for (int i = 0; i < mat.size(); ++i)
  43. {
  44. cout << "{";
  45.  
  46. for (int j = 0; j < mat[i].size(); ++j)
  47. {
  48. cout << mat[i][j];
  49.  
  50. if (j != mat[i].size() - 1)
  51. cout << ",";
  52. }
  53.  
  54. cout << "}" << endl;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement