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. ...
随机推荐
- Grunt.js 上手
Official Site gruntjs.org/docs/getting-started.html 或者看http://tgideas.qq.com/webplat/info/news_versi ...
- javascript Node操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 转: 关于viewport的理解
最近我做了一点儿针对手机的Web开发和相关研究.按说,Web自设计之初,就已经考虑了设备无关性.然而,现实总是不尽如人意. 我们知道大多数网页都是针对桌面显示器开发和测试的,但是手机屏幕通常要比桌面显 ...
- Qt多线程编程总结(二)——QMutex
QMutex类提供的是线程之间的访问顺序化. QMutex的目的是保护一个对象.数据结构或者代码段,所以同一时间只有一个线程可以访问它.(在Java术语中,它和同步关键字“synchronized”很 ...
- Java并发编程总结3——AQS、ReentrantLock、ReentrantReadWriteLock(转)
本文内容主要总结自<Java并发编程的艺术>第5章——Java中的锁. 一.AQS AbstractQueuedSynchronizer(简称AQS),队列同步器,是用来构建锁或者其他同步 ...
- 用Visual C++设计“精灵”窗体
随着Microsoft凭借Windows在操作系统上取得的巨大成绩,Windows用户界面也日益成为业界标准.统一的界面给广大用户对应用软件的学习与使用带来了很大方便.但每天都面对同一副面孔,日久天长 ...
- SPOJ LCS(Longest Common Substring-后缀自动机-结点的Parent包含关系)
1811. Longest Common Substring Problem code: LCS A string is finite sequence of characters over a no ...
- 鼠标放上去图片慢慢变大js 或 变大
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 新技能get: 使用whois查询不明网址的信息
1.站长之家-->Whois反查 http://whois.chinaz.com/ 进入whois.chinaz.com,输入要查询的网址,选择查询即可.
- linux下移动或者复制文件覆盖相同文件夹时,文件夹里面的每个文件都提示是否覆盖
链接地址:http://blog.chinaunix.net/uid-23683795-id-2391087.html # vi ~/.bashrc 如果你看到如下内容,以下命令都会用别名执行了, ...