timus online judge 1319. Hotel
A solution in c++
#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long ll;
#define sc1(a) scanf("%lld",&a)
ll arr[105][105];
int main()
{
ll row, col = 0, tc, t = 1;
sc1(tc);
// tc *= tc;
ll basicroe = 0, basiccol = col;
ll currow = 0, curcol = col;
for(ll i = tc-1; i >=0; i--){
ll row = 0, col = i;
while (row < tc && col < tc){
arr[row][col] = t++;
row++, col++;
}
}
for(ll i = 1; i < tc; i++){
ll row = i, col = 0;
while (row < tc && col < tc){
arr[row][col] = t++;
row++, col++;
}
}
for ( ll i = 0; i < tc; i++ ) {
for ( ll j = 0; j < tc; j++ ) {
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
0 Comments
If you have any doubts, Please let me know