UVa213 Message Decoding
来源:互联网 发布:nginx wiki 编辑:程序博客网 时间:2024/05/17 05:02
传送门:https://vjudge.net/problem/UVA-213
真的是感觉自己好垃圾,就这样的题竟然抠了一下午,最后发现导致程序错误的只是一对小括号,简直要抓狂了。。。
这道题的难度之一是输入的方式,需要自己设计一个read_code函数来接收多行输入,另一个需要解决的问题就是key和原字符的匹配,即设计match函数,要想一一对应,必须要唯一标识key值,这里可以用一个二维数组完美解决,key[digit_capacity][value] = char
另外要注意原字符串的输入可能包含空格,可以用上面的read_code函数来解决。
#include<stdio.h>#include<string.h>int match_code[8][129];int read_char();int read_code(int);int get_code();int main() { memset(match_code, 0, sizeof(match_code)); while(read_char()) { int value; int len; for(;;) { len = read_code(3); if(len == 0) break; for(;;) { value = read_code(len); if(value == (1 << len) - 1) break; printf("%c", match_code[len][value]); } } printf("\n"); memset(match_code, 0, sizeof(match_code)); getchar(); //不加这个getchar(),最后一组总是输不出来结果 } return 0;} int read_char() { for(int i = 1; i < 8; i++) for(int j = 0; j < (1 << i) - 1; j++) { int ch = getchar(); if(ch == EOF) return 0; if(ch == '\n' || ch == '\r') return 1; match_code[i][j] = ch; } return 1;}int read_code(int c) { int sum = 0; while(c--) { sum += (1 << c) * (get_code() - '0'); } return sum;}int get_code() { for(;;) { int ch = getchar(); if(ch != '\n' && ch != '\r') return ch; //在碰到换行符前,一直接收 }}
阅读全文
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
- Progress of 96Board Camera MIPI Mezzanine
- SoftMax回归简介及python代码实现
- 大学生职业生涯规划
- luogu3009 [USACO11JAN]利润Profits
- Bilibili Spider 经验总结
- UVa213 Message Decoding
- qsort
- RMQ与用RMQ做LCA
- CentOS下载安装Nginx, 详情配置Nginx和对Nginx进行性能优化
- 生成树协议STP和快速生成树协议RSTP的配置及原理
- 【猫猫的Unity Shader之旅】之高斯模糊
- 1073. 多选题常见计分法(20)
- 以知乎为例试探讨一种万能模拟登陆方式
- (二)操作系统设计技术知识重点笔记