-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage Decoding.cpp
More file actions
64 lines (60 loc) · 869 Bytes
/
Message Decoding.cpp
File metadata and controls
64 lines (60 loc) · 869 Bytes
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
#include <cstdio>
#include <cstring>
int code[8][1<<8];
int readchar()
{
for(;;)
{
int ch = getchar();
if(ch != '\r' && ch != '\n')
return ch;
}
}
int readint(int n)
{
int v = 0;
while(n--)
{
v = v * 2 + readchar() - '0';
}
return v;
}
int readcodes()
{
memset(code, 0, sizeof(code));
code[1][0] = readchar();
for(int len = 2; len <=7; len++)
{
for(int i = 0; i < (1 << len)-1; i++)
{
int ch = getchar();
if(ch == EOF)
return 0;
if(ch == '\r' || ch == '\n')
return 1;
code[len][i] = ch;
}
}
return 1;
}
int main()
{
while(readcodes())
{
for(;;)
{
int len = readint(3);
if(len == 0)
break;
for(;;)
{
int v = readint(len);
if(v == (1 << len)-1)
break;
putchar(code[len][v]);
}
}
putchar('\n');
}
return 0;
}