13300

来源:互联网 发布:js jsonarray 遍历 编辑:程序博客网 时间:2024/06/05 14:41


Numbers Game
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KBTotal submit users: 67, Accepted users: 65Problem 13300 : No special judgementProblem description

Youngkl likes playing numbers games, but some games like Sudoku are so simple for him. And then he wants to play a more difficult game. Do you want to play with him?

Let me introduce the rules of the game for you. For each input N, you should fill in the N*N table with the numbers(from 1 to N*N) and you should always start at the diagonal from the upper left corner. Go horizontal direction first, then vertical. Here are some examples for you, please find the law in the samples and complete the numbers game.

Input

Each line will contain one integer N (1<=N<=30).Process to end of file.

Output

For each set of input data, output N lines of the completed form (each line of N integers, separated by a space between each number).

Sample Input
34
Sample Output
1 2 34 6 75 8 91 2 3 45 8 9 106 11 13 147 12 15 16
Problem SourceHNU Contest 


#include <stdio.h>int main(){    int n;    while( scanf("%d",&n)!=EOF )        fun(n);    return 0;}int fun(int n){    int Ncnt;    int N[31][31];    int i,j,k;        Ncnt=n*n;    N[n][n]=Ncnt;    for(i=n;i>0;i--) {        j=n;        while(j>i) {            N[j][i]=Ncnt--;            j--;        }        k=n;        while(k>=i) {            N[i][k]=Ncnt--;            k--;        }    }    for(i=1;i<(n+1);i++) {        for(j=1;j<(n+1);j++) {            printf("%d",N[i][j]);            if(j!=n)                printf(" ");            else                 printf("\n");        }    }    return 0;}


0 0