ZOJ 3713 In 7-bit (题意不好理解,十进制、二进制、十六进制的转换问题)
考验理解能力的时候到了 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 (题意不好理解,十进制、二进制、十六进制的转换问题)的更多相关文章
- Javascript之旅——第十一站:原型也不好理解?
写到这篇,我的js系列也快接近尾声了,所以这个系列不会遗留js来实现面向对象的核心——原型,有些人说原型不好理解,其实嘛,要想系统 的理解原型,最便捷的方式就是看看经典的书,少看些博客,博客这东西只是 ...
- sugarcrm关于邮件设置几个不好理解的地方
陈沙克日志 把我的过程记录下来,以免以后忘了 2008-06-11 12:32 sugarcrm关于邮件设置几个不好理解的地方 最近看sugarcrm的使用,别的基本使用,没有什么问题,几天就 ...
- ZOJ 3713 In 7-bit
点我看题目 题意 : 这个题的英文叙述真的是太强了,真不知道哪里来的英文,完全看不懂,看了两个小时没弄懂真正的题意.就是给你一个字符串,先输出长度,但是长度要用二进制表示出来,二进制的低7位左边如果没 ...
- [ACM_模拟] ZOJ 3713 [In 7-bit 特殊输出规则 7bits 16进制]
Very often, especially in programming contests, we treat a sequence of non-whitespace characters as ...
- 用惯了jquery, 想用angularjs 还真不好理解
jquery 比较直白,什么都是操作dom 节点. angularjs 就好比 thinkphp, ci 等框架,有自己约定的格式和方式.需要遵循它的规则,研究中... 比如说我,用了很长事件的jqu ...
- 彻底理解mysql服务器的字符集转换问题
主要参考这三个文章: https://www.xiariboke.com/article/4147.html http://blog.sina.com.cn/s/blog_690c46500100k1 ...
- 深入理解Scala的隐式转换系统
摘要: 通过隐式转换,程序员可以在编写Scala程序时故意漏掉一些信息,让编译器去尝试在编译期间自动推导出这些信息来,这种特性可以极大的减少代码量,忽略那些冗长,过于细节的代码. 使用方式: 1. ...
- 转载:深入理解Scala的隐式转换系统
摘要: 通过隐式转换,程序员可以在编写Scala程序时故意漏掉一些信息,让编译器去尝试在编译期间自动推导出这些信息来,这种特性可以极大的减少代码量,忽略那些冗长,过于细节的代码. 使用方式: 1. ...
- 深入理解Scala的隐式转换
摘要: 通过隐式转换,程序员可以在编写Scala程序时故意漏掉一些信息,让编译器去尝试在编译期间自动推导出这些信息来,这种特性可以极大的减少代码量,忽略那些冗长,过于细节的代码. 使用方式: 1. ...
随机推荐
- pcap文件格式解析
pcap文件格式是常用的数据报存储格式,包括wireshark在内的主流抓包软件都可以生成这种格式的数据包 下面对这种格式的文件简单分析一下: pcap文件的格式为: 文件头 24字节 ...
- ssh无密登录
ssh登录一般两种方式: 1.密码登录 2.密钥验证无需密码 使用方式:1.生成密钥 2.将公钥追加到authorized_keys中,需要注意的是执行权限需为600,这里因而第一次添加使用的是> ...
- Error inflating class android.support.v7.widget.Toolbar
建立程序的时候出现的错误 style.xml中的 <!-- Base application theme. --> <style name="AppTheme" ...
- nodejs--express开发个人博客(2)
上一部分已经实现了视图的雏形,现在加上逻辑操作. 登陆.注册.文章发表都需要用到数据库的数据存取,用的比较多的就是mongodb了. MongoDB 是一个对象数据库,它没有表.行等概念,也没有固定的 ...
- elk 添加节点
elk 添加节点: cluster.name: es_cluster node.name: node03 path.data: /elk/elasticsearch/data path.logs: / ...
- ThinkPHP 3.1.2 视图-1
一.模板的使用 (重点) a.规则 模板文件夹下[TPL]/[分组文件夹/][模板主题文件夹/]和模块名同名的文件夹[Index]/和方法名同名的文件 [index].html(.tpl) 更换模板文 ...
- JavaScript 高级程序设计(第3版)笔记——chapter7:函数表达式
一.函数表达式的语法形式 匿名函数 var functionName = function(arg0, arg1, arg2) { //函数体 } 二.函数表达式没有函数提升 var a = 1; i ...
- php怎样求一个数组中最长的
<?php $arr = array( 0 => 'd', 1 => '68b3', 2 => 'a86', 3 => 'c9aa97b23b71d5c', 4 => ...
- python之filter过滤器
Python内建的filter()函数用于过滤序列. 和map()类似,filter()也接收一个函数和一个序列.和map()不同的时,filter()把传入的函数依次作用于每个元素,然后根据返回值是 ...
- OC中属性readwrite,readonly,assign,retain,copy,nonatomic 各是什么作用,在那种情况下用?
此次只做简单说明,不做代码演示! 1> readwrite:同时生成get方法和set方法的声明和实现 2> readonly:只生成get方法的声明和实现 3> assign:se ...