In 7-bit

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3713

题意:给定一个字符串,首先输出这个字符串的长度(以两位的十六进制的形式),如果长度以二进制表示,其位数从右往左每七位分为一段,除了最后的一段,其余段在最高位前加1,然后依次以十六进制输出,如果不足七位,直接以两位十六进制输出,如果长度为0,输出00。然后输出字符串的ASCII的十六进制形式。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 using namespace std;
 5 const int N=3000010;
 6 const int bit7=1<<7;
 7 char s[N];
 8 int main()
 9 {
10     int t;
11     scanf("%d%*c",&t);
12     while(t--)
13     {
14         gets(s);
15         int len = strlen(s);
16         if(len==0)
17         {
18             printf("%02X
",len);
19             continue;
20         }
21         while(len)
22         {
23             if(len < bit7)
24                 printf("%02X",len);
25             else
26                 printf("%02X",len%bit7+bit7);
27             len /= bit7;
28         }
29         for (int i = 0; s[i]; i++)
30         {
31             printf("%02X",s[i]);
32         }
33         puts("");
34     }
35     return 0;
36 }
View Code
原文地址:https://www.cnblogs.com/lahblogs/p/3587196.html