考验理解能力的时候到了 T^T

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).

  

题目大意:

  给定一个字符串,按照十六进制输出,但是对于字符串的长度的输出比较麻烦。

首先是将长度len转换成二进制,取后七位,如果除去后七位前边还有1那么就在第八位位置加上1,

  然后将len右移7位,继续上述步骤,

例如10001000100,那么第一次取出来的后七位就是1000100,因为前边还有1,

所以第一次取出来的变为11000100,然后将len右移7位得到1000,依次输出他们的十六进制就可以了

对于一个十进制的数先转换成二进制取后七位,再转换成十进制,就相当于十进制的数取后128位,也就是 len%128

Source Code:

#include <bits/stdc++.h>

using namespace std;

string str;

int main () {
int i, j, t, n, m, k, u, v; cin >> t;
getchar ();
while (t--) {
getline (cin, str);
int len = str.size (); if ( == len) {
printf ("00\n");
continue;
} int l = len;
while (l) {
int tmp = l % ;
l /= ;
if (l) {
tmp += ;
}
printf ("%02X", tmp);
}
for (i = ; i < len; ++i) {
printf ("%02X", str[i]);
}
printf ("\n"); } return ;
}

ZOJ 3713 In 7-bit (题意不好理解,十进制、二进制、十六进制的转换问题)的更多相关文章

  1. Javascript之旅——第十一站:原型也不好理解?

    写到这篇,我的js系列也快接近尾声了,所以这个系列不会遗留js来实现面向对象的核心——原型,有些人说原型不好理解,其实嘛,要想系统 的理解原型,最便捷的方式就是看看经典的书,少看些博客,博客这东西只是 ...

  2. sugarcrm关于邮件设置几个不好理解的地方

    陈沙克日志 把我的过程记录下来,以免以后忘了     2008-06-11 12:32 sugarcrm关于邮件设置几个不好理解的地方 最近看sugarcrm的使用,别的基本使用,没有什么问题,几天就 ...

  3. ZOJ 3713 In 7-bit

    点我看题目 题意 : 这个题的英文叙述真的是太强了,真不知道哪里来的英文,完全看不懂,看了两个小时没弄懂真正的题意.就是给你一个字符串,先输出长度,但是长度要用二进制表示出来,二进制的低7位左边如果没 ...

  4. [ACM_模拟] ZOJ 3713 [In 7-bit 特殊输出规则 7bits 16进制]

    Very often, especially in programming contests, we treat a sequence of non-whitespace characters as ...

  5. 用惯了jquery, 想用angularjs 还真不好理解

    jquery 比较直白,什么都是操作dom 节点. angularjs 就好比 thinkphp, ci 等框架,有自己约定的格式和方式.需要遵循它的规则,研究中... 比如说我,用了很长事件的jqu ...

  6. 彻底理解mysql服务器的字符集转换问题

    主要参考这三个文章: https://www.xiariboke.com/article/4147.html http://blog.sina.com.cn/s/blog_690c46500100k1 ...

  7. 深入理解Scala的隐式转换系统

    摘要: 通过隐式转换,程序员可以在编写Scala程序时故意漏掉一些信息,让编译器去尝试在编译期间自动推导出这些信息来,这种特性可以极大的减少代码量,忽略那些冗长,过于细节的代码.   使用方式: 1. ...

  8. 转载:深入理解Scala的隐式转换系统

    摘要: 通过隐式转换,程序员可以在编写Scala程序时故意漏掉一些信息,让编译器去尝试在编译期间自动推导出这些信息来,这种特性可以极大的减少代码量,忽略那些冗长,过于细节的代码.   使用方式: 1. ...

  9. 深入理解Scala的隐式转换

    摘要: 通过隐式转换,程序员可以在编写Scala程序时故意漏掉一些信息,让编译器去尝试在编译期间自动推导出这些信息来,这种特性可以极大的减少代码量,忽略那些冗长,过于细节的代码.   使用方式: 1. ...

随机推荐

  1. 两台linux机器文件传输之scp

    0.写在前面:一定要注意我们是否有源文件的读权限,是否有目标文件夹的写权限!没有的话要先把权限设置好! *.设置权限的方法:切换到有权限操作文件或文件夹的用户,利用chmod命令修改权限 1.安装: ...

  2. HTML+CSS笔记 CSS笔记集合

    HTML+CSS笔记 表格,超链接,图片,表单 涉及内容:表格,超链接,图片,表单 HTML+CSS笔记 CSS入门 涉及内容:简介,优势,语法说明,代码注释,CSS样式位置,不同样式优先级,选择器, ...

  3. 25_Downloading An Image

    一个App,从网上下载一张图片(给出图片地址),重新命名,然后保存到手机中,再从手机中取出显示在屏幕上. 难度不大,就是找图片很蛋疼,百度搜索出来的过一会儿会失效,Google搜索出来的有些需要FQ, ...

  4. Delphi中使用TXMLDocument控件应注意的问题

    今天写了一个类,其中用到了TXMLDocument控件.这个控件我是要动态生成的. 但是却遇到了非常奇怪的问题,下面分享一下 procedure TMainForm.Button1Click(Send ...

  5. 盘点:移动服务 #AzureChat

    感谢大家帮助我们顺利推出史无前例的 #AzureChat.移动服务和 Notification Hub 是 Windows Azure 平台上令人振奋的服务.我们很高兴能借这次在线讨论的机会,倾听各位 ...

  6. C++的一些编程规范(基于google)

    1.所有头文件都应该使用#define 防止头文件被多重包含,命名格式可以参考<PROJECT>_<PATH>_<FILE>_H 2.使用前置声明尽量减少.h文件中 ...

  7. Js用正则表达式验证字符串

    js 常用正则表达式表单验证代码 作者: 字体:[增加 减小] 类型:转载 js 常用正则表达式表单验证代码,以后大家就可以直接使用了. 正则表达式使用详解 简介 简单的说,正则表达式是一种可以用于模 ...

  8. [译]Stairway to Integration Services Level 12 - 高级日志配置

    介绍 本文中,我们将结合之前学习的时间冒泡,日志记录,以及复制模型.建立一个自定义的SSIS包日志模型. SSIS Task事件回顾    Reviewing SSIS Task Events 在做实 ...

  9. UILabel显示html文本

    NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\ ...

  10. UIScreen的 bound、frame、scale属性

    CGRect bound = [[UIScreen mainScreen] bounds];  // 返回的是带有状态栏的Rect   CGRect frame = [[UIScreen mainSc ...