U E D R , A S I H C RSS

압축알고리즘/정욱&자겸

압축알고리즘/정욱&자겸


압축알고리즘/자겸&정욱


~cpp 
#include <iostream>
using namespace std;

int main(){
	char zip[80];
	int i=1;
	int num, count=1;
	char temp;
	
	cout << "압축할 영문자열을 입력하세요 :";
	cin >> zip;
	num = strlen(zip);
	temp = zip[0];
	while (i != num){
		if (temp == zip[i]) count++;
		else {
			cout << count << temp;
			temp = zip[i];
			count = 1;
		}
		i++;
	}
	cout << count << temp << endl;
	return 0;
}

해제알고리즘/자겸&정욱

~cpp 
#include <iostream>
#include <cstdlib> 
using namespace std;

int main(){
	char zip[80];
	int i = 0, j = 0;
	char temp;
	char dig[30];
		
	cout << "해제할 코드를 입력하세요 :";
	cin >> zip;
	int num = strlen(zip);
	temp = zip[0];
	while (i != num){
		if (int(temp) >= 48 && int(temp) <= 57) dig[j++] = temp; 
		else {
			dig[j] = '\0';
			for (int k = 0; k < atoi(dig); k++){
				cout << temp;
			}
			j = 0;
		}
		i++;
		temp = zip[i];
	}
	cout << endl;
	return 0;
}

DPCM


해제 알고리즘

~cpp 
#include <iostream>
using namespace std;

int main(){
	char zip[80];
	int i = 1, j = 0;
	int temp;
	char ch;
	
	cout << "해제할 코드(Ver.2)를 입력하세요 :";
	cin >> zip;
	int num = strlen(zip);
	temp = int(zip[0]);
	while (i != num){
		if (zip[i] == '-') {
			i++;
			ch = char(temp - (int(zip[i]) - 48));
		}
		else ch = char(temp + (int(zip[i]) - 48));
		cout << ch;
		i++;
	}
	cout << endl;
	return 0;
}

압축 알고리즘

~cpp 
#include <iostream>
using namespace std;

int main(){
	char zip[80];
	int i = 0, j = 0;
	int temp;
	int dig;
	
	cout << "압축할 코드(Ver.2)를 입력하세요 :";
	cin >> zip;

	cout << zip[0];
	int num = strlen(zip);
	temp = int(zip[0]);
	while (i != num){
		dig = int(zip[i]) - temp;
		cout << dig;
		i++;
	}
	cout << endl;
	return 0;
}

압축 업그레이드

~cpp 
#include <iostream>
using namespace std;

int main(){
	char zip[80];
	int i = 0, j = 0;
	int temp;
	int dig;
	
	cout << "압축할 코드(Ver.3)를 입력하세요 :";
	cin >> zip;
	
	cout << zip[0];
	int num = strlen(zip);
	temp = int(zip[0]);
	while (i != num){
		dig = int(zip[i]) - temp;
		if (dig > 9) {
			temp = zip[i];
			dig = int(zip[i]) - temp;
			cout << zip[i];
		}
		if (dig < -9) {
			temp = zip[i];
			dig = int(zip[i]) - temp;
			cout << zip[i];
		}
		
		cout << dig;
		i++;
	}
	cout << endl;
	return 0;
}

해제 업그레이드

~cpp 
축알고리즘
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:23
Processing time 0.0143 sec