华为统计连续字符次数并进行输出
#include<iostream>
#include<string>
#include<map>;
#include <stdio.h>
using namespace std;
int main(int argc,char* argv[]){
string str;
cin>>str;
char sub_str;
int i=0;
for(;i<str.size();i++){
sub_str = str[i];
int count =0;
for(int j=i;j<str.size();j++){
if(sub_str == str[j]){
i=j;
count++;
}else{
cout<<sub_str;
cout<<count;
//i=j-1;
sub_str = str[j];
break;
}
}
if(i==str.size()-1){
cout<<sub_str;
cout<<count;
}
}
system("pause");
return 0;
}