📄 lzw_yima.cpp
字号:
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,string> pos;
string bb[4097]={"#0","#1","#2","#3","#4","#5","#6","#7","#8","#9","#10","#11","#12","#13","#14",
"#15","#16","#17","#18","#19","#20","#21","#22","#23","#24","#25","#26","#27","#28","#29","#30","#31"};
string b[4097]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z","A","B","C","D","E","F"};
void strtab()
{
for(int i=0;i<=3;i++)
pos[bb[i]]=b[i];
}
string int2str( int num)
{
if (num == 0 )
return " 0 " ;
string str = "" ;
while (num)
{
str = ( char )(num % 10 + 48 ) + str;
num /= 10 ;
}
return str;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("rn.txt","w",stdout);
string data,code,old,temp;
int i,j,mk[1000],k,l;
string codestream[500];
strtab();
while(cin>>data)
{
basic_string<char>::iterator ie;
for(l=0,i=0,ie=data.begin();ie!=data.end();i++,ie++)
if(*ie=='#')
{ mk[l++]=i;
cout<<i;
}
mk[l]=i;
k=0;
code.assign(data,mk[0],mk[1]-mk[0]);
cout<<code<<endl;
codestream[k++]=pos[code];
old=code;
code.assign(data,mk[1],mk[2]-mk[1]);
cout<<code<<endl;
//out<<"fsdf"<<code<<endl<<"fdsf";
j=4,i=2;
system("pause");
while(1)
{
temp.erase();
if(pos[code]!="")
{
codestream[k++]=pos[code];
//cout<<"codestream="<<codestream[k-1]<<endl;
temp=pos[old];
temp+=*pos[code].begin();
//cout<<"temp="<<temp<<endl;
string s="#"+int2str(j++);
//cout<<"s="<<s<<endl;
pos[s]=temp;
old=code;
// system("pause");
}
else
{
temp=pos[old];
temp+=*pos[code].begin();
//cout<<"temp="<<temp<<endl;
codestream[k++]=temp;
//cout<<"codestream="<<codestream[k-1]<<endl;
string s="#"+int2str(j++);
//cout<<"s="<<s<<endl;
pos[s]=temp;
old=code;
// system("pause");
}
if(i==l) break;
code.assign(data,mk[i++],mk[i]-mk[i-1]);
}
printf("***\n");
for(i=0;i<k;i++)
cout<<" "<<codestream[i];
printf("\nasdfa\n");
}
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -