【HDOJ】2707 Steganography

本文介绍了一个简单的字符串转换程序,该程序使用C语言实现了一种特定的字符串编码和解码方式。通过对输入字符串进行特定的位操作来实现从原始字符到特定编码的转换,并能够将这些编码再转换回原始的字符形式。

简单字符串,读懂题,很容易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 }

 

 

转载于:https://www.cnblogs.com/bombe1013/p/3680712.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值