Skip to content

Instantly share code, notes, and snippets.

@samebchase
Created April 21, 2014 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samebchase/11137784 to your computer and use it in GitHub Desktop.
Save samebchase/11137784 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<vector>
using std::vector;
using std::cout;
using std::endl;
using std::cin;
int main(void)
{
int rows, cols;
cin >> rows >> cols;
cout << "rows: " << rows << ", cols: " << cols << endl;
vector<vector<int>> matrix;
vector<int> row;
for (int row_idx = 0; row_idx < rows; ++row_idx) {
for (int col_jdx = 0; col_jdx < cols; ++col_jdx) {
int tmp;
cin >> tmp;
row.push_back(tmp);
}
matrix.push_back(row);
row.clear();
}
for (auto row : matrix) {
for (auto elt : row) {
cout << elt << " ";
}
cout << endl;
}
return 0;
}
@samebchase
Copy link
Author

Sample data

2 3
1 2 3
4 5 6
$ ./a.out < input.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment