标签:
题目大意:Sample inputTNM AEIOU 0010101100011 1010001001110110011 11000 $#**0100000101101100011100101000 Sample outputTAN ME ##*\$ |
#include<cstdio>
#include<cstring>
using namespace std;
int readchar() {//读入字符,并且过滤开头回车或换行
for (;;) {
int ch = getchar();
if (ch != ‘\n‘ && ch != ‘\r‘)
return ch;
}
}
int readint(int c) {//计算二进制大小
int v = 0;
while (c--) {
v = v * 2 + readchar() - ‘0‘;
}
return v;
}
int code[8][1 << 8];//1 << 8相当于1*2^8, [x][y]表示长度为y(长度为x)的字符
bool readcodes() {//读入数据,并且判断是否读入成功
memset(code, 0, sizeof(code));
code[1][0] = readchar();
for (int len = 2; len <= 7; ++len) {
for (int i = 0; i < (1 << len) - 1; ++i) {
int ch = getchar();
if (ch == EOF) return false;//读到文件结束,说明读入失败
if (ch == ‘\n‘ || ch == ‘\r‘) return true;//读到换行或回车说明读入成功
code[len][i] = ch;
}
}
return true;
}
int main() {
while (readcodes()) {
for (;;) {
int len = readint(3);
if (len == 0) break;
for (;;) {
int v = readint(len);
if (v == (1 << len) - 1) break;//全1时退出
putchar(code[len][v]);
}
}
putchar(‘\n‘);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4571838.html