storing matrix in vector

Solutions on MaxInterview for storing matrix in vector by the best coders in the world

showing results for - "storing matrix in vector"
Carla
26 Apr 2017
1#pragma GCC optimize("Ofast")
2#pragma GCC target("avx,avx2,fma")
3#pragma GCC optimization("unroll-loops")
4#include <bits/stdc++.h>
5#define Code ios_base::sync_with_stdio(false);
6#define by cin.tie(NULL);
7#define black_heretic cout.tie(NULL);
8#define fl(n) for (int i = 0; i < n; i++)
9#define rl(m, n) for (int i = n; i >= m; i--)
10typedef long long ll;
11#define read(x) ll x; cin >> x
12using namespace std;
13
14// Remark: NIL.
15
16void solve() {
17    int i, j, n, m;
18    cin >>  m >> n; // rows and columns resp.
19    int arr[m][n];
20    // Original:
21    // vector<pair<int, int>> myVec (N, std::make_pair(-1, -1));
22    // The second argument to that constructor is the initial value that the N pairs will take.
23    vector<pair<int, int>> cordinates;
24    for(i = 0; i < m; ++i){
25        for(j = 0; j < n; ++j){
26            cin >> arr[i][j];
27            if(arr[i][j] == 1){
28                cordinates.push_back(make_pair(i, j));
29            }
30        }
31    }
32    for (auto it = cordinates.begin(); it!=cordinates.end(); ++it) {
33        cout << it->first << " " << it->second << endl;
34    }
35
36return;
37}
38 
39signed main(){
40    Code by black_heretic
41    // read(t); while(t--)
42        solve();
43    return 0;
44}
similar questions
queries leading to this page
storing matrix in vector