博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[ACM_模拟] ZOJ 3713 [In 7-bit 特殊输制]出规则 7bits 16进
阅读量:5923 次
发布时间:2019-06-19

本文共 3117 字,大约阅读时间需要 10 分钟。

 

 

Very often, especially in programming contests, we treat a sequence of non-whitespace characters as a string. But sometimes, a string may contain whitespace characters or even be empty. We can have such strings quoted and escaped to handle these cases. However, a different approach is putting the length of the string before it. As most strings are short in practice, it would be a waste of space to encode the length as a 64-bit unsigned integer or add a extra separator between the length and the string. That's why a 7-bit encoded integer is introduced here.

To store the string length by 7-bit encoding, we should regard the length as a binary integer. It should be written out by seven bits at a time, starting with the seven least-significant (i.e. 7 rightmost) bits. The highest (i.e. leftmost) bit of a byte indicates whether there are more bytes to be written after this one. If the integer fits in seven bits, it takes only one byte of space. If the integer does not fit in seven bits, the highest bit is set to 1 on the first byte and written out. The integer is then shifted by seven bits and the next byte is written. This process is repeated until the entire integer has been written.

With the help of 7-bit encoded integer, we can store each string as a length-prefixed string by concatenating its 7-bit encoded length and its raw content (i.e. the original string).

Input

There are multiple test cases. The first line of input is an integer T indicating the number of test cases.

Each test case is simply a string in a single line with at most 3000000 characters.

Output

For each test case, output the corresponding length-prefixed string in uppercase hexadecimal. See sample for more details.

Sample Input

342yukkuri shiteitte ne!!!https://en.wikipedia.org/wiki/Answer_to_Life,_the_Universe,_and_Everything#Answer_to_the_Ultimate_Question_of_Life.2C_the_Universe_and_Everything_.2842.29

Sample Output

0234321779756B6B75726920736869746569747465206E652121219A0168747470733A2F2F656E2E77696B6970656469612E6F72672F77696B692F416E737765725F746F5F4C6966652C5F7468655F556E6976657273652C5F616E645F45766572797468696E6723416E737765725F746F5F7468655F556C74696D6174655F5175657374696F6E5F6F665F4C6966652E32435F7468655F556E6976657273655F616E645F45766572797468696E675F2E323834322E3239

Author: WU, Zejun

Contest: The 10th Zhejiang Provincial Collegiate Programming Contest

 

题目大意:给定一个字符串,用字符串ASC2码16进制数输出 ,并在前面输出字符串长度的16进制,输出长度的规则是 先输出长度的二进制数的后七位的十六进制(如果左边还有1 则这在后七位前面加上个1再输出  然后二进制数右移动七位,直到左边没有1)   注:所有16数都必须为两位!

解题思路:首先按照他的规则输出字符串长度,再输出16进制的字符串。[这里涉及到printf的输出格式相关知识]

相关链接:printf输出格式:

 

1 #include 
2 #include
3 #define MAXN 3000010 4 using namespace std; 5 char str[MAXN]; 6 int main(){ 7 int ncase,len,tlen; 8 scanf("%d",&ncase); 9 gets(str);10 while(ncase--){11 gets(str);12 tlen=len=strlen(str);13 while(1){14 printf("%02X",(len&127)+(len>127?128:0));15 len>>=7;16 if(len==0) break;17 }//用他的规则输出字符串长度的7bits 16进制数18 for(int i=0;i
http://www.cnblogs.com/zjutlitao/p/3590431.html
你可能感兴趣的文章
Linux 练习题-4网络 问答
查看>>
在Oracle VM VirtualBox下安装centos 注意事项
查看>>
Python学习:函数(function)
查看>>
Python学习:列表(list)
查看>>
动态代理
查看>>
查看浏览器版本
查看>>
1965: [Ahoi2005]SHUFFLE 洗牌
查看>>
黑马程序员---7k面试题(二)---------------银行业务调度系统
查看>>
玩转EsLint
查看>>
一个preg_replace()参数均为数组多次替换的实例理解
查看>>
一个苏州IT人的5年挨踢经历-------经历篇(之一)
查看>>
第十三周项目3-立体类族共有的抽象类
查看>>
[转]C++ 类中的static成员的初始化和特点
查看>>
实时搜索的优化
查看>>
实战:ajax带参数请求slim API
查看>>
1. jsp中<base target='' />标签用法
查看>>
Problem F: 等式
查看>>
Java多线程 - 线程的生命周期
查看>>
OOCSS的概念和思路
查看>>
Markdown 快速入门指南
查看>>