【HDOJ】2707 Steganography

简单字符串,读懂题,很容易AC。

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 char buf[350], line[85], des[70];
 5 
 6 int main() {
 7     int i, k, tmp, len;
 8     int ib, id;
 9 
10     memset(buf, 0, sizeof(buf));
11     ib = 0;
12 
13     while (gets(line) != NULL) {
14         len = strlen(line);
15         if (len==1 && line[0]=='#')
16             break;
17         if (len==1 && line[0]=='*') {
18             id = 0;
19             for (i=0; i<ib; i+=5) {
20                 tmp = (buf[i]<<4) + (buf[i+1]<<3) + (buf[i+2]<<2) + (buf[i+3]<<1) + (buf[i+4]);
21                 if (tmp == 0)
22                     des[id] = ' ';
23                 else if (tmp == 27)
24                     des[id] = '\'';
25                 else if (tmp == 28)
26                     des[id] = ',';
27                 else if (tmp == 29)
28                     des[id] = '-';
29                 else if (tmp == 30)
30                     des[id] = '.';
31                 else if (tmp == 31)
32                     des[id] = '?';
33                 else
34                     des[id] = tmp-1+'A';
35                 ++id;
36             }
37             des[id] = '\0';
38             printf("%s\n", des);
39             ib = 0;
40             memset(buf, 0, sizeof(buf));
41         } else {
42             k = 0;
43             for (i=0; i<len; ++i) {
44                 if (k && line[i]!=' ') {
45                     buf[ib++] = !(k&1);
46                     k = 0;
47                 } else if (line[i] == ' '){
48                     ++k;
49                 }
50             }
51         }
52     }
53 
54     return 0;
55 }

 

 

posted on 2014-04-22 16:01  Bombe  阅读(117)  评论(0编辑  收藏  举报

导航