//统计字符串中字母出现的次数,水题。
//注意:并不是统计字母总共出现的次数,如:ABBCCABC=A2B2CABC;
#include<iostream>
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int time;
cin>>time;
string str;
int count;
while(time--)
{
cin >> str;
int len = str.size();
for(int i = 0; i < len; i++)
{
count = 1;
while(str[i] == str[i + 1])
{
count++;
i++;
}
if(count == 1)
cout << str[i];
else
cout << count << str[i];
}
cout << endl;
}
return 0;
}
//std::ios::sync_with_stdio(false);
//为了使cin,cout速度加快,详情请查看我另一条博客。
【HDU】(字符串)1020_Encoding C++解法
最新推荐文章于 2023-09-20 09:16:16 发布