LZW压缩及解压C++实现

##LZW算法的压缩与解压
LZW压缩

#include 
#include 
#include 
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {//对编码字符进行解码 
	int n;
	map LzwMap;  //定义键值对存放 
	cout<<"输入codes的个数"<>n;
	int a[n];
	for(int i=0;i>a[i];
	}
	LzwMap[1]="A",LzwMap[2]="B",LzwMap[3]="C";//初始化词典分别对A/B/C进行1/2/3编码
	string s="NIL";
	int count=4;//新字符的编码 
	int k;
	string str;
	for(int i=0;i::iterator iter;
		bool flag=false;
		string value;
		for(iter=LzwMap.begin();iter!=LzwMap.end();iter++){//搜素字典中键为k的值 
			if (iter->first==k){
				flag=true;
				value=iter->second;
				break;	
			}	
		}
		if(flag==true){//若存在字典中,则输出值 
			cout<

LZW解压

#include 
#include 
#include 
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {//对编码字符进行解码
	int n;
	map LzwMap;  //定义键值对存放
	cout<<"输入codes的个数"<>n;
	int a[n];
	for(int i=0;i>a[i];
	}
	LzwMap[1]="A",LzwMap[2]="B",LzwMap[3]="C";//初始化词典分别对A/B/C进行1/2/3编码
	string s="NIL";
	int count=4;//新字符的编码
	int k;
	string str;
	for(int i=0;i::iterator iter;
		bool flag=false;
		string value;
		for(iter=LzwMap.begin();iter!=LzwMap.end();iter++){//搜素字典中键为k的值
			if (iter->first==k){
				flag=true;
				value=iter->second;
				break;
			}
		}
		if(flag==true){//若存在字典中,则输出值
			cout<

你可能感兴趣的:(c/c++)