Skip to content

Commit 418af6e

Browse files
committed
[Array] swea-1210
1 parent 14dcfdb commit 418af6e

File tree

5 files changed

+1083
-0
lines changed

5 files changed

+1083
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
| 05 | | [Codility-Lesson4 MissingInteger](./src/Array/MissingInteger) | |
9999
| 06 | | [Codility-Lesson4 MaxCounters](./src/Array/MaxCounters) | |
100100
| 07 | | [SWEA-1208 Flatten](./src/Array/swea1208) | |
101+
| 08 | | [SWEA-1210 Ladder1](./src/Array/swea1210) | |
101102

102103
### Stack
103104

src/Array/swea1210/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## [SW Expert Academy - 1210] Ladder1
2+
3+
![image](https://user-images.githubusercontent.com/22045163/106583093-0a6ff880-6588-11eb-895a-7be1ca14d594.png)
4+
![image](https://user-images.githubusercontent.com/22045163/106583132-16f45100-6588-11eb-8748-657fca76c9a7.png)
5+
![image](https://user-images.githubusercontent.com/22045163/106583202-2ecbd500-6588-11eb-97ec-dac365f31d43.png)
6+
![image](https://user-images.githubusercontent.com/22045163/106583230-38553d00-6588-11eb-945c-2405bef60d3b.png)
7+
![image](https://user-images.githubusercontent.com/22045163/106583404-689cdb80-6588-11eb-8e10-52acbd864987.png)

src/Array/swea1210/Solution.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package Array.swea1210;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Solution {
7+
8+
final static int T = 10, N = 100;
9+
static int[][] ladder;
10+
static int[] current;
11+
12+
public static void main(String[] args) throws Exception {
13+
System.setIn(new FileInputStream("src/Array/swea1210/input.txt"));
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
16+
for (int t = 1; t <= T; t++) {
17+
br.readLine();
18+
ladder = new int[N][N];
19+
20+
for (int i = 0; i < N; i++) {
21+
StringTokenizer st = new StringTokenizer(br.readLine());
22+
for (int j = 0; j < N; j++) {
23+
ladder[i][j] = Integer.parseInt(st.nextToken());
24+
if (ladder[i][j] == 2) current = new int[]{i, j};
25+
}
26+
}
27+
28+
while (current[0] >= 0) {
29+
boolean rotated = false;
30+
for (int d = -1; d <= 1 && !rotated; d += 2) {
31+
while (0 <= current[1]+d && current[1]+d < N && ladder[current[0]][current[1]+d] == 1) {
32+
rotated = true;
33+
current[1] += d;
34+
}
35+
}
36+
current[0] --;
37+
}
38+
39+
System.out.println("#" + t + " " + current[1]);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)