U E D R , A S I H C RSS

압축알고리즘/홍선,수민

RLE


~cpp 
#include <iostream>  
#include <fstream>  
using namespace std;  
  
char buffer[100]={0};  
int max,count;  
int start_Number, end_Number;  
bool ing_Number=false;  
  
bool test(int index)  
{  
        if ( index <max && 48<= (int)buffer[index] && (int)buffer[index] <= 57 ){  
                if(ing_Number)  
                        end_Number= index;  
                if(!ing_Number)  
                {  
                        ing_Number=true;  
                        start_Number = index;  
                        end_Number= index;  
                }  
                test(index+1);  
        }  
        else if(ing_Number)  
        {  
                ing_Number=false;  
                return true;  
        }  
        else return false;  
}  
void extract()  
{  
        ifstream fin("input_e.txt");  
        int i=0,j, number;  
        while(fin.get(buffer[i]))  
        {  
                i++;  
        }  
    max = i;  
  
        for(i=0;i<max ; i++)  
        {  
                number=0;  
                if(test(i))  
                {  
                        for(j=start_Number ;j<= end_Number;j++)  
                                number = number*10 +(int)(buffer[j])-48;  
                        for(int k=0;k<number;k++)  
                                cout << buffer[end_Number+1];  
                }  
        }  
        cout << endl;  
  
}  
 
void compression() 
{ 
        char buffer[100];
		int i=0;
    ifstream fin("input_e.txt"); 
        while(fin.get(buffer[i])) 
        { 
			i++;
			while(buffer[i]==buffer[i+1]) 
                        count++;
		}

		cout << buffer[i] << count;

		
         
 
 
 
} 
  
int main()  
{  
        compression();  
                extract(); 
                return 0;  
}  


DPCM

~cpp 
#include <iostream> 
#include <fstream> 
using namespace std; 
 
void compression() 
{ 
        ifstream fin("input_c.txt"); 
        char buffer, standard; 
 
        standard = fin.get(); 
        cout << standard << '0'; 
 
    while(fin.get(buffer))  
    { 
		if( (standard-buffer) < -9 || 9 < (standard-buffer) ) {
			standard = buffer;
			cout << standard;
		}
        cout << int(buffer-standard); 
    }  
        cout << endl; 
  
 
 
} 
 
void extract() 
{ 
        bool minus=false; 
        ifstream fin("input_e2.txt"); 
        char buffer; 
        char su; 
        fin.get(buffer); 
        while(fin.get(su)) 
        { 
                if(su=='-') 
                        minus=true; 
			else if( su < 48 || 57< su )
			{
				buffer =su;
			}
                else if(minus) 
                { 
                        cout << char(int(buffer)-(int(su)-48)); 
                        minus=false; 
                } 
                else 
                { 
                        cout << char(int(buffer)+int(su)-48); 
                } 
        } 
        cout << endl; 
} 
int main() 
{ 
        compression(); 
        extract(); 
         
        return 0; 
} 
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:23
Processing time 0.0125 sec