拓冰建站拓冰建站
首页 / 资讯中心 / 正文

22、<简单>总结相同的数字

#include iostream #include string using namespace std; int main() { // 程序功能字符串压缩单个字母不标数字连续重复标长度字母 cout 输入要求仅小写英文字母长度不超过255 endl; cout 请输入待压缩字符串; string str; cin str; string result; int length str.size(); int index 0; while (index length) { char current str[index]; int count 1; // 统计当前字母连续出现多少次 while (index 1 length str[index 1] current) { count; index; } // 多于1个才拼接数字 if (count 1) { result result to_string(count); } result current; index; } cout \n压缩完成压缩后的字符串 result endl; return 0; }
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门