-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotel.java
48 lines (47 loc) · 938 Bytes
/
Hotel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Timus OJ - 1319
* Hotel
*/
import java.io.*;
import java.util.*;
public class Hotel {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(f.readLine());
int[][] grid = new int[n][n];
int iStart = 0;
int jStart = n - 1;
int num = 1;
int i, j;
while (jStart >= 0) {
j = jStart;
i = iStart;
while (j < n) {
grid[i][j] = num;
num++;
i++;
j++;
}
jStart--;
}
jStart = 0;
iStart = 1;
while (iStart < n) {
i = iStart;
j = jStart;
while (i < n) {
grid[i][j] = num;
num++;
i++;
j++;
}
iStart++;
}
for (int k = 0; k < n; k++) {
for (int m = 0; m < n; m++) {
System.out.print(grid[k][m] + " ");
}
System.out.println();
}
}
}