给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续出现的个数+字符”。比如字符串AAAABCCDAA会被编码成4A1B2C1D2A。
#include<iostream>
#include<string>
using namespace std;
int
main(){
string str;
cin>>str;
int
s=str.size();
int
t=
1
;
for
(
int
i=
0
;i<s;i++){
if
(str[i]==str[i+
1
]){
++t;
}
else
{
cout<<t;
t=
1
;
cout<<str[i];
}
}
return
0
;
}
|