Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <sstream>
- std::vector<std::vector<int>> readMatrice(int& rowCount) {
- std::cin >> rowCount;
- std::cin.ignore();
- std::vector<std::vector<int>> vec;
- while (true) {
- std::string line;
- getline(std::cin, line);
- std::vector<int> row;
- std::istringstream istr(line);
- int num;
- while (istr >> num) {
- row.push_back(num);
- }
- vec.push_back(row);
- if (vec.size() == rowCount) {
- break;
- }
- }
- return vec;
- }
- void printMatrice(std::vector<std::vector<int>>& matrice) {
- std::cout << std::endl;
- for (auto& row : matrice) {
- for (int i = 0; i < row.size(); ++i) {
- std::cout << row[i] << ' ';
- }
- std::cout << std::endl;
- }
- }
- int main() {
- int rowCount = 0;
- std::vector<std::vector<int>> matrice = readMatrice(rowCount);
- printMatrice(matrice);
- }
Advertisement
Add Comment
Please, Sign In to add comment