Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- #define ppb pop_back
- int main()
- {
- _test
- {
- int n, m;
- cin>>n>>m;
- vector<vector<int>> a(n, vector<int> (m, 0));
- if(n == 4)
- {
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=m; j++)
- a[i-1][j-1] = i + (j-1)*4;
- }
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- cout<<a[i][j]<<" ";
- cout<<"\n";
- }
- continue;
- }
- else
- {
- int x = 1;
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- a[i][j] = x++;
- }
- }
- int x = 0;
- for(int i=0; i<n; i+=2, x++)
- {
- for(int j=0; j<m; j++)
- cout<<a[i][j]<<" ";
- cout<<"\n";
- }
- for(int i=1; i<n; i+=2, x++)
- {
- for(int j=0; j<m; j++)
- cout<<a[i][j]<<" ";
- cout<<"\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment