华为(C++实现字符串压缩程序)
2015-03-28 11:02
781 查看
#include<iostream> #include<string> using namespace std; void string_zip(string input,string &output) { if(input.empty()) return ; char last='\0'; char current; int count=0; for(int i=0;i<input.size();++i) { current=input[i]; if(current==last||last=='\0') { count++; last=current; } else { if(count>1) { output.push_back(count+'0'); } output.push_back(last); count=1; last=current; } } if(count>1) output.push_back(count+'0'); output.push_back(last); } int main() { string input("aabbbbccd"); string output; string_zip(input,output); cout<<output<<endl; system("pause"); return 0; }
相关文章推荐
- C++实现的Huffman压缩解压缩程序及相应程序框架的设计
- 程序目的:实现c++整型和字符数组,字符串的相互转化
- 华为2014年机试题【字符串压缩】-【C语言/C++】
- 字符串压缩C++实现
- 华为机试题2014 字符串过滤程序 java实现
- 华为机试题—字符串压缩 c++
- 算法思维——字符串压缩程序(华为2014校园招聘的机试题目)
- C/C++面试程序题(一)——字符串反转、链表反转的递归、非递归实现
- 华为2014年机试题【字符串压缩】-【C语言/C++】
- 华为上机笔试之通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。
- 字符串压缩之C++实现
- 第十六题 2014华为机试题 字符串压缩程序
- 字符串压缩之C++实现
- 华为上机密码验证合格程序C++实现
- 华为字符串压缩程序
- 华为面试题:请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。
- C++程序学习之实现手机通讯录功能模拟
- 简单LinuxC程序关于任意长整数相加(字符串实现)
- C++ 哈夫曼树对文件压缩、加密实现代码
- C++ 实现多语言程序开发研究与Xtreme ToolkitPro的使用(一)