Problem link
A solution in c++
#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long ll;
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)
#define mx 100005
#define mod 10000007
set<ll>vc;
set<ll>::iterator it;
int main()
{
//freopen ("input.txt", "r", stdin);
ll tc,n;
sc1(tc);
ll arr[tc][tc];
for(ll i = 0; i < tc; i++)
for(ll j = 0; j < tc; j++)
cin>>arr[i][j];
for(ll i = 0; i < tc*2-1; i++){
for(ll j = 0; j <= i && j<tc; j++){
ll k = i - j;
//cout<<k<<endl;
if(k >= 0 && k < tc) cout<<arr[k][j]<<" ";
}
}
}
0 Comments
If you have any doubts, Please let me know