U E D R , A S I H C RSS

압축알고리즘/주영&재화

DPCM 압축

~cpp 
#include <iostream>
#include<string>
using namespace std;
int main()
{
	string input;
	cin  >> input;

	cout << input[0];
	for(int i=0;i<input.size() ;i++)
	{
		cout << (int)(input[i] - input[0]);
		
	}

}

DPCM 압축 업데이트

~cpp 
#include <iostream>
#include<string>
using namespace std;
int main()
{
	string input;
	cin  >> input;

	cout << input[0];
	char standard = input[0];
	
	for(int i=0;i<input.size() ;i++)
	{
		if((int)(input[i] - standard)<10)
			cout << (int)(input[i] - standard);
		else
		{
			standard = input[i];
			cout << standard;
			cout << (int)(input[i] - standard);
		}
		
	}

}


DPCM 해제

~cpp 
#include <iostream>
#include<string>
using namespace std;
int main()
{
	string input;
	cin  >> input;

	for(int i=1;i<input.size();i++)
	{
		cout << (char)(input[0] + (input[i] - '0'));
	}
	cout << endl;

}

DPCM 해제 업그레이드

~cpp 
#include <iostream> 
#include<string> 
using namespace std; 
int main() 
{ 
        string input; 
        cin  >> input; 
		char standard = input[0];
        for(int i=1;i<input.size();i++) 
        { 
			if(input[i]>='0' && input[i]<='9')
                cout << (char)(standard + (input[i] - '0')); 
			else
			{
				standard = input[i];
				cout<<(char)standard;
				//cout << (char)(standard + (input[i] - '0'));
			}
        } 
        cout << endl; 
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:23
Processing time 0.0079 sec