当前位置: 首页 > news >正文

zoj3713 7Bit

意思是把一行字符串的长度按照找7位一个字节输出,如果长度能够存在7位里,字节的最高位置0,否则只输出7位并且输出字节的最高位置1,直到全部输出长度.

要注意的是有空串要输出00,其他按照16进制输出就可以了,注意要补0.

 1 #include <cstdio>
 2 #include <cstring>
 3 using namespace std;
 4 char a[3000008];
 5 int main(){
 6     int T;
 7     scanf("%d", &T);
 8     getchar();
 9     while(T--){
10         gets(a);
11         int len = strlen(a);
12         if(len == 0) printf("00");
13         while(len){
14             int t = len % 128;
15             len /= 128;
16             if(len) t += 128;
17             printf("%02X", t);
18         }
19         len = strlen(a);
20         for(int i = 0; i < len; ++i)
21             printf("%02X", a[i]);
22         printf("\n");
23     }
24 }
In 7-bit

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

3
42
yukkuri 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

023432
1779756B6B75726920736869746569747465206E65212121
9A0168747470733A2F2F656E2E77696B6970656469612E6F72672F77696B692F416E737765725F746F5F4C6966652C5F7468655F556E6976657273652C5F616E645F45766572797468696E6723416E737765725F746F5F7468655F556C74696D6174655F5175657374696F6E5F6F665F4C6966652E32435F7468655F556E6976657273655F616E645F45766572797468696E675F2E323834322E3239

转载于:https://www.cnblogs.com/wushuaiyi/p/3650210.html

相关文章:

  • USACO Healthy Holsteins DFS
  • 易经读书笔记16 雷地豫
  • 【MM系列】MB1A MB1B MB1C MB11 MIGO的区别解析
  • tf.nn.conv2d 卷积
  • IE6、IE7兼容querySelectorAll和querySelector方法-最终版本
  • 【Linux】Shell批量修改文件名
  • MySQL 查询当天、本周,本月、上一个月的数据
  • NHibernate3.2+Asp.net MVC3+Extjs 4.0.2项目实践(五):Extjs树形导航菜单
  • 利用指针间隔的输出字符串中的字符
  • Java中Httpsession是如何实现的?
  • 《SpringMVC从入门到放肆》十二、SpringMVC自定义类型转换器
  • 洛谷 P1616 疯狂的采药
  • 【BW系列】SAP 讲讲BW/4 HANA和BW on HANA的区别
  • Shell的一些基本概念
  • 剑指Offer——二叉搜索树的第K个节点
  • php的引用
  • 「前端早读君006」移动开发必备:那些玩转H5的小技巧
  • 【附node操作实例】redis简明入门系列—字符串类型
  • 10个确保微服务与容器安全的最佳实践
  • Java 多线程编程之:notify 和 wait 用法
  • Java新版本的开发已正式进入轨道,版本号18.3
  • leetcode388. Longest Absolute File Path
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • Linux学习笔记6-使用fdisk进行磁盘管理
  • Logstash 参考指南(目录)
  • NSTimer学习笔记
  • Octave 入门
  • React的组件模式
  • Swoft 源码剖析 - 代码自动更新机制
  • 彻底搞懂浏览器Event-loop
  • 排序算法学习笔记
  • 区块链将重新定义世界
  • 如何实现 font-size 的响应式
  • 为什么要用IPython/Jupyter?
  • 小程序上传图片到七牛云(支持多张上传,预览,删除)
  • 小李飞刀:SQL题目刷起来!
  • 远离DoS攻击 Windows Server 2016发布DNS政策
  • 正则表达式
  • 06-01 点餐小程序前台界面搭建
  • AI又要和人类“对打”,Deepmind宣布《星战Ⅱ》即将开始 ...
  • 湖北分布式智能数据采集方法有哪些?
  • 摩拜创始人胡玮炜也彻底离开了,共享单车行业还有未来吗? ...
  • #include<初见C语言之指针(5)>
  • #调用传感器数据_Flink使用函数之监控传感器温度上升提醒
  • #我与Java虚拟机的故事#连载05:Java虚拟机的修炼之道
  • #我与虚拟机的故事#连载20:周志明虚拟机第 3 版:到底值不值得买?
  • ( 用例图)定义了系统的功能需求,它是从系统的外部看系统功能,并不描述系统内部对功能的具体实现
  • (android 地图实战开发)3 在地图上显示当前位置和自定义银行位置
  • (C++17) std算法之执行策略 execution
  • (第二周)效能测试
  • (附源码)计算机毕业设计ssm电影分享网站
  • (附源码)计算机毕业设计SSM基于java的云顶博客系统
  • (免费领源码)python#django#mysql校园校园宿舍管理系统84831-计算机毕业设计项目选题推荐
  • (四)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (一)u-boot-nand.bin的下载