`
dato0123
  • 浏览: 915338 次
文章分类
社区版块
存档分类
最新评论

HDU1020 Encoding

 
阅读更多

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1020
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

#include<iostream>
#include
<string>
usingnamespacestd;

voiddoProcess(string&str)
{
intcount,i,j;
for(i=0;i<str.length();)
{
count
=1;
for(j=i+1;j<str.length();++j)
{
if(str[i]==str[j])
{//记录相同的字符个数
count++;
}

else
break;
}

if(count>1)
{
cout
<<count<<str[i];
}

else
{
cout
<<str[i];
}

i
=j;//更新起始位置
}

cout
<<endl;
}

intmain()
{
intcaseNum,i;
stringstrTmp;
while(cin>>caseNum)
{
for(i=0;i<caseNum;++i)
{
cin
>>strTmp;
doProcess(strTmp);
}

}

return0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics