RLE ¶
~cpp #include <iostream> #include <fstream> using namespace std; void main() { ifstream fin("input.txt"); //형식은 3b11a같이 char ch; int num; do{ fin >> num; // 포인트... fin.get(ch); for ( int i = 0 ; i < num ; i++ ) cout << ch; }while( !fin.eof() ); }
압축 ¶
~cpp #include <iostream> using namespace std; void main() { char ch; ch = cin.get(); cout << ch; char initial = ch; do { cout << initial - ch; cin.get(initial); }while(!(initial == '\n')); }
~cpp #include <iostream> using namespace std; void main() { char ch; ch = cin.get(); cout << ch; char initial = ch; do { cout << initial - ch; cin.get(initial); if((initial-ch>9||initial-ch<-9)) { ch = initial; cout << ch; } }while(!(initial == '\n')); }
압축알고리즘