-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChuckNorris.cs
56 lines (50 loc) · 1.27 KB
/
ChuckNorris.cs
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
using System;
// https://www.codingame.com/ide/puzzle/chuck-norris-codesize
class Solution
{
static string dump(int bit, int count)
{
string res = (bit == 0) ? "00 " : "0 ";
while (count-- > 0) res += "0";
return res;
}
static void Main(string[] args)
{
string code = "";
int b = 0;
int count = 0;
int bits = 0;
foreach (char raw in Console.ReadLine())
{
int ch = raw;
for (int i=0; i<7; ++i)
{
int and = ch & 64;
if (count == 0)
{
b = ch&64;
count = 1;
}
else if (and == b)
{
count += 1;
}
else
{
string work = dump(b,count);
code += (code.Length == 0) ? "" : " ";
code += work;
b = and;
count = 1;
}
ch <<= 1;
}
}
if (count != 0)
{
code += (code.Length == 0) ? "" : " ";
code += dump(b,count);
}
Console.WriteLine(code);
}
}