encoding.cc.txt
来自「Ulm大学2003-2004年竞赛题」· 文本 代码 · 共 49 行
TXT
49 行
// Problem Run Length Encoding// Algorithm Straight-Forward// Runtime O(n)// Author Walter Guttmann// Date 2003.12.07#include <fstream>#include <iostream>#include <string>using namespace std;ifstream in("encoding.in");int main(){ string line; while (getline(in, line)) { for (string::iterator it = line.begin() ; it != line.end() ; ) { int rep = 1; while (rep < 9 && (it+rep) != line.end() && *it == *(it+rep)) ++rep; // A sequence of min(rep,9) identical characters starts at *it. if (rep > 1) { cout << rep << *it; it += rep; } else { cout << 1; for ( ; it != line.end() && ((it+1) == line.end() || *it != *(it+1)) ; ++it) { cout << *it; if (*it == '1') cout << *it; } // Either a repetitive sequence begins at *it, or it reached the end of line. cout << 1; } } cout << endl; } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?