1. 程式人生 > >HDOJ 2153 仙人球的殘影(水題)

HDOJ 2153 仙人球的殘影(水題)

java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            if (n==0) {
                break;
            }
            if (n==1) {
                System.out
.println(" 1"); continue; } int m = n*n-(n-2)*(n-2); for (int i = 0; i < n; i++) { if (i==0) { for (int j = 0; j < n; j++) { System.out.printf("%3d",j+1); } System.out
.println(); continue; } if (i==n-1) { for (int j = 0; j < n; j++) { System.out.printf("%3d",m-n-j+2); } System.out.println(); continue; } for
(int j = 0; j < n; j++) { if (j==0) { System.out.printf("%3d",m-i+1); continue; } if (j==n-1) { System.out.printf("%3d",n+i); System.out.println(); continue; } System.out.print(" "); } } } sc.close(); } }