Algorithm第四版算法 C++实现(二十八) 您所在的位置:网站首页 游程编码怎么写 Algorithm第四版算法 C++实现(二十八)

Algorithm第四版算法 C++实现(二十八)

2024-07-17 10:27| 来源: 网络整理| 查看: 265

游程编码的原理很简单,他适用于以零开头的二进制文件的压缩,原理就是统计有多少个0,或1,将其转化为数字。 需要压缩的文件 000000000001111111111111111 00000000111111111000000000 000000000001111111111100000000 00000000000111111111111 000000000001111111111111 00000000000011111111111 需要解压的文件 11 16 8 9 9 11 11 8 11 12 11 13 12 11

class RLC { private: std::ifstream *f; public: RLC(std::ifstream &file) { f = &file; } void expend() { bool b=0; std::string str; while (!f->eof()) { std::getline(*f, str); for (auto s : split(str, " ")) { int n = std::stoi(s); for (int i = 0; i std::string str; while (!f->eof()) { int count = 0; std::getline(*f, str); char c = str[0]; for (int i = 0; i count++; } else { printf("%d ", count); c = str[i]; count = 1; } } printf("%d\n",count); } } }; 运行结果

在这里插入图片描述 在这里插入图片描述 由于我们的c++没有split方法……所以,我从网上抄了一个,效果还不错。 转载自此处

std::vector split(std::string str, std::string pattern) { std::string::size_type pos; std::vector result; str += pattern;//扩展字符串以方便操作 int size = str.size(); for (int i = 0; i std::string s = str.substr(i, pos - i); result.push_back(s); i = pos + pattern.size() - 1; } } return result; }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有