UVa 213:Message Decoding
2017-04-11 18:28
253 查看
题目传送门:https://cn.vjudge.net/problem/UVA-213
0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, … , 1011, 1110, 00000, …
输入头对应的字符存储在 codes[len][value] 数组中(表示长度为len且编码为value的字符),例如:
codes[1][0] 代表 0 对应的 key
codes[2][0] 代表 00 对应的 key
codes[2][1] 代表 01 对应的 key
codes[2][2] 代表 10 对应的 key
codes[3][0] 代表 000 对应的 key
…
AC代码:
0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, … , 1011, 1110, 00000, …
输入头对应的字符存储在 codes[len][value] 数组中(表示长度为len且编码为value的字符),例如:
codes[1][0] 代表 0 对应的 key
codes[2][0] 代表 00 对应的 key
codes[2][1] 代表 01 对应的 key
codes[2][2] 代表 10 对应的 key
codes[3][0] 代表 000 对应的 key
…
AC代码:
#include <stdio.h> #include <memory.h> char codes[8][130]; // 用于保存编码的字符 int readChar() { // 读取一个字符,注意剔除回车和换行 while (true) { int ch = getchar(); if (ch != '\n' && ch != '\r') return ch; } } int readInt(int len) { // 读取二进制字符串,len为长度,返回对应的十进制数 int digit = 0; while (len--) digit = 2 * digit + readChar() - '0'; return digit; } int readHeader() { // 读取编码头 memset(codes, 0, sizeof(codes)); codes[1][0] = readChar(); // 先读取一个看是不是EOF if (EOF == codes[1][0]) return 0; for (int len = 2; len <= 7; ++len) { for (int i = 0; i < (1 << len) - 1; ++i) { int ch = getchar(); if (EOF == ch) return 0; if ('\n' == ch || '\r' == ch) return 1; codes[len][i] = ch; } } return 1; } void printCodes() { for (int len = 1; len <= 7; ++len) { for (int i = 0; i < (1 << len) - 1; ++i) putchar(codes[len][i]); putchar('\n'); } } int main() { while (readHeader()) { //printCodes(); while (true) { int len = readInt(3); if (0 == len) break; while (true) { int x = readInt(len); if (x == (1 << len) - 1) break; putchar(codes[len][x]); } } putchar('\n'); } return 0; }
相关文章推荐
- 算法竞赛入门经典第四章例题4-4 Message Decoding UVA - 213
- UVa-213 Message Decoding
- UVA_213: Message Decoding
- Message Decoding UVA - 213
- Message Decoding (UVA-213)
- 算法竞赛入门经典(紫书)第四章——Message Decoding UVA-213
- Message dicoding, ACM/ICPC World Finals 1991, UVa 213
- uva_213_Message Deocding
- UVa 213 信息解码Message Decoding
- ACM 粗心永远AC不了系列——UVa 213 Message Decoding(World Finals1991,字符串) |二维数组的妙用
- UVA 12897 Decoding Baby Boos
- uva 213 - Message Decoding(二进制编码)
- UVa 213 - Message Decoding
- UVa 213 Message Decoding (信息解码)
- Uva.213 Message Decoding
- UVA-213-Message Decoding 信息编码 基础模拟题 直观的新手思路+详细注释
- uva -213 Message Decoding
- uva 213 Message Decoding
- UVa213
- UVa 213 Message Decoding(World Finals1991,字符串)