
— Oh! You are the cool programmer, I know. Couldn’t you help me? I need just a printout of the table with an arrangement of the labels in the cells. But not in such way as THIS will hang on the wall, but as THIS stands on the table of my workshop. Yes, I understand that you are busy, but you are busy every time! Preparations to the Ural Championship, tests, solutions… So what? If you can’t do it yourself – entrust your competitors with this task. They are the best programmers all over the world, aren’t they? I don’t believe that they couldn’t print the desired table having the size of the square! I would never believe it! So… Excellent! I will take the desired printout away after the contest.
Input
The input consists of the only one integer N (1 ≤ N ≤ 100), which is the size of the square.
Output
You are to write a program that outputs the table of numbers, as they would be arranged when THIS would stand in the workshop. The label with number 1 should be in the upper right corner and other numbers should be arranged along the diagonals from the top to the bottom. The label with the last number (N*N) should be in the lower left corner.
Sample
input | output |
---|---|
3 |
4 2 1 |
Problem Author: Stanislav Vasilyev Problem Source: VIII Collegiate Students Urals Programming Contest. Yekaterinburg, March 11-16, 2004
// Ural Problem 1319. Hotel
// Verdict: Accepted
// Submission Date: 01:06:08 16 Jan 2014
// Run Time: 0.031s
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/// [解题方法]
// 简单题,直接找矩阵规律即可 #include<stdio.h> int a[][]; void solve()
{
int N, i, j, k, M, t;
scanf("%d", &N);
M = N * (N + ) / ;
t = ;
j = ; k = ;
while(k <= M) {
for(j = N - ; j >= ; j--) {
t = j;
i = ;
while(t <= N - ) {
a[i++][t++] = k++;
}
}
}
for(i = ; i < N; i++) {
t = i;
for(j = ; j < N - i; ){
a[t++][j++] = k++;
}
}
for(i = ; i < N; i++) {
for(j = ; j < N; j++) {
if(j == ) printf("%d", a[i][j]);
else printf(" %d", a[i][j]);
}
printf("\n");
}
} int main()
{
solve();
return ;
}