1 // 2008 ACM Mid-Central USA Regional Programming Contest
 2 // Solution to Problem H: "Steganography" [easy/moderate]
 3 // Eric Shade, Missouri State University
 4 
 5 #include <iostream>
 6 #include <fstream>
 7 using namespace std;
 8 
 9 char decode[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ',-.?";
10 
11 int main() {
12     ifstream in("steg.in");
13     int spaces = 0;
14     int bits = 0;
15     int code = 0;
16     char c;
17 
18     while ((c = in.get()) != '#') {
19         if (c == ' ') {
20             ++spaces;
21         } else {
22             if (spaces > 0) {
23                 code = (code << 1) + 1 - (spaces & 1);
24                 spaces = 0;
25                 if (++bits == 5) {
26                     cout << decode[code];
27                     code = bits = 0;
28                 }
29             }
30             if (c == '*') {
31                 if (bits > 0) {
32                     cout << decode[code << (5 - bits)];
33                     code = bits = 0;
34                 }
35                 cout << endl;
36             }
37         }
38     }
39 
40     in.close();
41 }