Message Decoding
UVA - 213
题目传送门
emmmm,此题按照紫书上的思路来即可,要么太复杂
AC代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
int readchar()
{for(;;) {int ch=getchar();if(ch!='\r'&&ch!='\n') return ch;}
}
int readint(int c)
{int v=0;while(c--) {v=v*2+readchar()-'0';}return v;
}
int code[8][1<<8];
int readcodes()
{ms(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 0;if(ch=='\n'||ch=='\r')return 1;code[len][i]=ch;}}return 1;
}
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);while(readcodes()){for(;;) {int len=readint(3);if(len==0)break;for(;;) {int v=readint(len);if(v==(1<<len)-1) break;putchar(code[len][v]);}}putchar('\n');}return 0;
}