⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encoding.cc.txt

📁 Ulm大学2003-2004年竞赛题
💻 TXT
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -