考验理解能力的时候到了 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. bzoj 1007 : [HNOI2008]水平可见直线 计算几何

    题目链接 给出n条直线, 问从y轴上方向下看, 能看到哪些直线, 输出这些直线的编号. 首先我们按斜率排序, 然后依次加入一个栈里面, 如果刚加入的直线, 和之前的那条直线斜率相等, 那么显然之前的会 ...

  2. C指针(转)

    第一章 指针的概念 指针是一个特殊的变量,它里面存储的数值被解释成为内存里的一个地址. 要搞清一个指针需要搞清指针的四方面的内容:指针的类型,指针所指向的 类型,指针的值或者叫指针所指向的内存区,还有 ...

  3. C#调用Matlab生成的dll方法

    其实整个过程比较简单,但是需要心细一点. 需要的工具:VS2005及以上版本,MATLAB2008B及以上版本,另外非常重要的需要安装一个MATLAB Compiler Runtime,这个文件(MC ...

  4. Java GUI图形界面开发工具

    Applet 应用程序     一种可以在 Web 浏览器中执行的小程序,扩展了浏览器中的网页功能. 缺: 1.需要下载 Applet 及其相关文件 2.Applet 的功能是受限制的 优: 3.无需 ...

  5. HDU 1240 Asteroids!

    三维广搜 #include <cstdio> #include <iostream> #include <cstring> #include <queue&g ...

  6. php:根据中文裁减字符串函数方法

    define(CHARSET, 'UTF-8'); // 系统默认编码 /** * 根据中文裁减字符串 * @param $string - 字符串 * @param $length - 长度 * @ ...

  7. Servlet、SPringMVC、Struts等防止表单反复提交的多种处理方法

    第一种处理方法(非拦截器): 眼下这样的方法不建议,由于JSP规范不建议写JAVA代码.这样的能够方便另外一种处理方法的理解,另外一种方法引入拦截器的思想,原理基本一样,模仿Struts的Token机 ...

  8. T-SQL函数及用法--转

    转自http://www.cnblogs.com/qixuejia/archive/2010/07/14/1777105.html 1. 聚合函数 (1) AVG 函数功能返回组中值的平均值.空值将被 ...

  9. No.2小白的HTML+CSS心得篇

    今天要强调的重点是分析把握好HTML标签的两个方面: 1.标签的用途(用途指的是用来干什么,有什么作用)在专业术语叫作 语义化. 举个列子:<br/> 换行的作用 见了它就明白它的语义就是 ...

  10. 从开发到部署,使用django创建一个简单可用的个人博客

    本文参考于: 简书-Django搭建简易博客教程:http://www.jianshu.com/p/d15188a74104 自强学堂-Django基础教程:http://www.ziqiangxue ...