首页 > 代码库 > URAL 1319 Hotel

URAL 1319 Hotel

还是斜着数

 1 import java.util.Scanner; 2  3 public class P1319 4 { 5     public static void main(String args[]) 6     { 7         try (Scanner cin = new Scanner(System.in)) 8         { 9             while (cin.hasNext())10             {11                 int sum = 1;12                 int n = cin.nextInt();13                 int a[][] = new int[n][n];14                 for (int k = 0; k < 2 * n - 1; k++)15                     for (int j = 0; j < n; j++)16                     {17                         int i = k - j;18                         if (i >= 0 && i < n)19                             a[j][i] = sum++;20                     }21                 for (int i = 0; i < n; i++)22                 {23                     for (int j = n - 1; j >= 0; j--)24                         System.out.print(a[i][j] + " ");25                     System.out.println();26                 }27             }28         }29     }30 }

 

URAL 1319 Hotel