UVa213 Message Decoding
来源:互联网 发布:js validate取消验证 编辑:程序博客网 时间:2024/05/24 02:51
这道题的难点有两处。
1.新手可能会觉得分行的01串处理起来比较困难。其实只要写一个函数readint(int len),在忽略输入流中的换行符的情况下,读取长度为len的二进制数,并将其转化为十进制数返回,就可以把输入流模拟成一个连续的01串了。readint函数中可以使用一个函数readchar(),返回输入流中下一个不为换行符的字符。
2.不知道如何高效地将二进制码转化成字符串中的对应字符。如果使用string与int之间的映射未免过于损耗性能;那么可以使用一个数组M[len][num]来表示长度为len,十进制数为num的二进制码所代表的字符在编码头中的位置,可以在程序开头进行预处理。
代码实现详见下
#include<bits/stdc++.h> using namespace std;char s[260];char s1[2][50000];int M[8][1 << 8], cnt, cur, pt, len;int readchar() { char ch; ch = getchar(); while (ch == '\n'||ch == '\r')ch = getchar(); return ch;}int readint(int c){ int ans = 0; while (c--) { ans = ans * 2 + readchar() - '0'; } return ans;}int main(){ //freopen("in.txt", "r", stdin); for (int i = 1; i < 8; i++) { int k = 1 << i; k--; for (int j = 0; j < k; j++) { M[i][j] = cnt++; } } while (cin.getline(s, 260)) { while (len = readint(3)) { int maxn = (1 << len) - 1, num; while ((num=readint(len)) < maxn) { printf("%c", s[M[len][num]]); } }printf("\n"); cin.get(); }}
阅读全文
0 0
- UVA213 - Message Decoding
- UVa213 Message Decoding
- UVa213 - Message Decoding
- UVA213----Message Decoding
- UVA213 UVALive5152 Message Decoding
- UVa213-Message Decoding
- UVa213 Message Decoding
- UVa213 Message Decoding
- UVA213 Message Decoding(二进制)
- 水题:UVa213- Message Decoding
- 算法竞赛入门经典 UVa213 Message Decoding
- Message Decoding
- Message Decoding
- 算法竞赛入门经典(第二版) 例题4-4 信息编码(Message Decoding) UVa213 Finals1991 (二进制)
- uva -213Message Decoding
- UVa 213 - Message Decoding
- UVaOJ-213 Message Decoding
- UVA【213】 Message Decoding
- idea 如何运行maven项目
- stm32串口发送数据,丢失字节问题分析
- 测试用例基本概念
- 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-H-Skiing
- Django06_model field
- UVa213 Message Decoding
- [日推荐]『单身脱脱脱』给单身狗发福利啦!
- 腾讯地图 省市县门店数量及信息标记显示
- Oracle中的存储过程简单例子
- 【干货收藏】数据库技术百问_数据库从起步到进阶必备
- GHO文件转iso文件能启动安装
- 定义View元素和他们的属性
- iOS应用层加密相关
- HDFS读写流程