compress.cc
// Beispiel: Simple compression // Verwendung: cat Filename | Thisprog #include <iostream.h> void out(const int count, const char c) { if (c == '\\') cout << "\\" << c << c << count + 1 << flush; else cout << "\\" << c << count + 1 << flush; } void out(const char c) { if (c == '\\') cout << c << c << flush; else cout << c << flush; } int main(void) { char p, c; int count; if (cin.read(&p, 1)) { count = 0; while (cin.read(&c, 1)) { if ( p == c ) { count++; continue; } if (count) { out(count, p); count = 0; } else out(p); p = c; } if (count) out(count, p); else out(p); } }
5. Einheit
© 1997 Gottfried Rudorfer, C++-AG, Lehrveranstaltungen, Abteilung für Angewandte Informatik, Wirtschaftsuniversität Wien, 11/11/1998 |