mstoyanov7

Untitled

Jun 7th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5.  
  6. std::vector<std::vector<int>> readMatrice(int& rowCount) {
  7. std::cin >> rowCount;
  8. std::cin.ignore();
  9. std::vector<std::vector<int>> vec;
  10. while (true) {
  11. std::string line;
  12. getline(std::cin, line);
  13. std::vector<int> row;
  14.  
  15. std::istringstream istr(line);
  16. int num;
  17. while (istr >> num) {
  18. row.push_back(num);
  19. }
  20. vec.push_back(row);
  21.  
  22. if (vec.size() == rowCount) {
  23. break;
  24. }
  25. }
  26. return vec;
  27. }
  28.  
  29. void printMatrice(std::vector<std::vector<int>>& matrice) {
  30. std::cout << std::endl;
  31. for (auto& row : matrice) {
  32. for (int i = 0; i < row.size(); ++i) {
  33. std::cout << row[i] << ' ';
  34. }
  35. std::cout << std::endl;
  36. }
  37. }
  38.  
  39. int main() {
  40. int rowCount = 0;
  41. std::vector<std::vector<int>> matrice = readMatrice(rowCount);
  42. printMatrice(matrice);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment