In 7-bit ZOJ
来源:互联网 发布:手机通话变声器软件 编辑:程序博客网 时间:2024/05/22 05:02
In 7-bit
ZOJ - 3713Very 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).
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.
For each test case, output the corresponding length-prefixed string in uppercase hexadecimal. See sample for more details.
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
0234321779756B6B75726920736869746569747465206E652121219A0168747470733A2F2F656E2E77696B6970656469612E6F72672F77696B692F416E737765725F746F5F4C6966652C5F7468655F556E6976657273652C5F616E645F45766572797468696E6723416E737765725F746F5F7468655F556C74696D6174655F5175657374696F6E5F6F665F4C6966652E32435F7468655F556E6976657273655F616E645F45766572797468696E675F2E323834322E3239
code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char a[3000003];int main(){ int t; cin >> t; getchar(); while(t--){ gets(a); int len = strlen(a); int l = len; if(!l){ printf("00\n"); } else{ while(l){ int tmp = l % 128;//取后七位数字 l /= 128;//右移七位 if(l){ tmp += 128;//第八位上变成1 } printf("%02X",tmp); } int i; for(i = 0; i < len; i++){ printf("%02X",a[i]); } puts(""); } } return 0;}
- In 7-bit ZOJ
- zoj 3713 In 7-bit
- ZOJ 3713 In 7-bit
- zoj 3713 In 7-bit
- ZOJ 3713 In 7-bit
- ZOJ 3713 In 7-bit
- ZOJ 3713 In 7-bit
- ZOJ 3713 In 7-bit
- ZOJ 3713 In 7-bit 解题报告
- ZOJ 3713In 7-bit(模拟)
- ZOJ 3713 In 7-bit(数学啊 )
- ZOJ 3713 In 7-bit (题目巨难懂)
- ZOJ 3713 In 7-bit(进制转换)
- zoj 3713 In 7-bit(题目特难懂,十进制、二进制、十六进制的转换问题)
- ZOJ-3713-In 7-bit【10th浙江省赛】【位运算】
- ZOJ 3713 10th省赛 I In 7-bit【位运算】
- zoj 2417 Lowest Bit
- zoj 2417 Lowest Bit
- Seetaface 安装使用教程
- AOP和OOP区别(手动滑稽)
- linux 安装mysql
- SpringCloud 教程 | 第四篇:断路器(Hystrix)
- C# 实时折线图,波形图
- In 7-bit ZOJ
- C# 导出文件时设置进度条
- 重现Redis--数据结构与对象(二)
- Spring基础---AOP使用拓展
- ssm+shiro整合 (未测试版本)
- [三代] 获取BADI对象的两种方法
- AngularJs获取传递参数方法
- cdn 内容发布网络
- 为什么要用implements Serializable