-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.cs
More file actions
58 lines (51 loc) · 1.37 KB
/
5.cs
File metadata and controls
58 lines (51 loc) · 1.37 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
/*
[D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
*/
string line = Console.ReadLine()!;
int i, n = (line.Length + 1) / 4;
List<char>[] stack = new List<char>[n];
List<char>[] list = new List<char>[n];
for (i = 0; i < n; ++i)
{
stack[i] = new List<char>();
list[i] = new List<char>();
}
do
{
for (i = 0; i < n; ++i)
{
char c = line[i * 4 + 1];
if (char.IsLetter(c))
{
stack[i].Insert(0, c);
list[i].Insert(0, c);
}
}
line = Console.ReadLine()!;
} while (line.Length != 0);
while (true)
{
string? str = Console.ReadLine();
string[]? op = str?.Split(' ');
if (op is ["move", var countStr, "from", var fromStr, "to", var toStr])
{
int count = int.Parse(countStr), from = int.Parse(fromStr) - 1, to = int.Parse(toStr) - 1;
for (; count > 0; --count)
{
stack[to].Add(stack[from][^1]);
stack[from].RemoveAt(stack[from].Count - 1);
list[to].Add(list[from][^count]);
list[from].RemoveAt(list[from].Count - count);
}
}
else break;
}
Console.WriteLine("P1: " + string.Join("", stack.Select(s => s.Count != 0 ? $"{s[^1]}" : "")));
Console.WriteLine("P2: " + string.Join("", list.Select(s => s.Count != 0 ? $"{s[^1]}" : "")));