using System using System IO using System Collections Generic using Sy

 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program ////Ритуля
{
static char[] CreateTree(int n)
{
int m1 = 1, m2 = 1, level = 1, m, k;
char[] z = new char[33000];
z[1] = 'a';
while (level < n)
{
for (k = m1; k <= m2; k++)
{
m = 2 * k;
switch (z[k])
{
case 'a':
{
z[m] = 'b';
z[m + 1] = 'c';
break;
}
case 'b':
{
z[m] = 'c';
z[m + 1] = 'a';
break;
}
case 'c':
{
z[m] = 'a';
z[m + 1] = 'b';
break;
}
}
}
level++;
m1 *= 2;
m2 = m2 * 2 + 1;
}
return z;
}
static char[] RouteTree(int n, char[] z)
{
int k = 1, m1, m2, r = 0;
for (int i = 1; i < n; i++) k *= 2;
m1 = k;
m2 = 2 * k - 1;
for (int i = m1; i <= m2; i++)
{
k = i;
if (z[k] == 'a')
{
r++;
Console.WriteLine();
while (k > 0)
{
Console.Write("{0} ", z[k]);
k /= 2;
}
Console.Write(r);
}
}
return z;
}
static void Main(string[] args)
{
int n = Int32.Parse(Console.ReadLine());
char[] z = CreateTree(n);
z = RouteTree(n, z);
Console.WriteLine(z[0]);
}
}
}