????LZW???????????????????????y??????????????????????????????? LZW???????Unisys?????????Ч???2003?????????????????????
????????????????LZW???????????????????????????????????????????(cai)??(bi)?????struct && ????????????????ɡ?

#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
struct Node{
int pre;//?????????????
char c;//??????
}KDA[65535];
int cnt??P??Q;
char W??V;
void Init(){//?256??????????ASCII??????
for(int i = 0;i < 256; i ++){
KDA[i].pre = -1;
KDA[i].c = i;
}
cnt = 256;
P = -1;
}
void Out(int x){                            //????????????????????λ?????????????
if(KDA[x].pre != -1){
Out(KDA[x].pre);
}
else {
V = KDA[x].c;
}
printf("%c"??KDA[x].c);
}
void Search(){
int flag = 0;
for(int i = 0;i < cnt;i ++){
if(KDA[i].pre == P && KDA[i].c == W){//??????????????????????
P = i;
flag = 1;
}
}
if(!flag){                  //??????????????????????????????????????
KDA[cnt].pre = P;
KDA[cnt].c = W;
printf("%03X "??P);
P = (int)W;
cnt ++;
}
}
void Research(){
Out(Q);
if(P != -1){                //??????λ?????????????λ????????????????????λ???????μ??????????
KDA[cnt].pre = P;
KDA[cnt].c = V;
cnt ++;
}
}
void Compress(){<span style="white-space:pre"></span>//???????
Init();
freopen("LZWin.txt"??"r"??stdin);
freopen("LZWch.txt"??"w"??stdout);
while((W = getchar()) && W != EOF){
Search();
}
printf("%03X
"??P);
}
void Decompress(){<span style="white-space:pre"></span>//???????
Init();
freopen("LZWch.txt"??"r"??stdin);
freopen("LZWout.txt"??"w"??stdout);
while(scanf("%03X"??&Q)!= EOF){
Research();
}
}
int main(){
Compress();
Decompress();
return 0;
}