-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathJava.java
More file actions
68 lines (59 loc) · 1.98 KB
/
Java.java
File metadata and controls
68 lines (59 loc) · 1.98 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/****************************************/
/* */
/* CodinGame.com Solutions by pathosDev */
/* */
/* Puzzle: Ghost Legs */
/* Difficulty: Easy */
/* Date solved: 22.02.2019 */
/* */
/****************************************/
import java.util.Scanner;
public class Solution
{
public static void main(String[] args)
{
//Read diagram size.
Scanner scanner = new Scanner(System.in);
String[] line = scanner.nextLine().split(" ");
int W = Integer.parseInt(line[0]);
int H = Integer.parseInt(line[1]);
//Read top labels and create start indices.
String[] T = scanner.nextLine().split(" ");
int[] Ti = new int[T.length];
for (int i = 0; i < Ti.length; i++)
{
Ti[i] = i;
}
//Read diagram lines.
for (int i = 0; i < H - 2; i++)
{
line = scanner.nextLine().split("\\|");
//Search for horizontal lines.
for (int j = 0; j < line.length; j++)
{
if (line[j].equals("--"))
{
//Check where the horizontal line is and change indices.
for (int k = 0; k < Ti.length; k++)
{
if (Ti[k] == j - 1)
{
Ti[k] += 1;
}
else if (Ti[k] == j)
{
Ti[k] -= 1;
}
}
}
}
}
//Read bottom labels.
String[] B = scanner.nextLine().split(" ");
//Print result.
for (int i = 0; i < T.length; i++)
{
System.out.println(T[i] + B[Ti[i]]);
}
}
}