HDU1020 Encoding

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1020

#include<iostream>
#include 
<string>
using namespace std;

void doProcess(string& str)
{
    
int count,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;
}

int main()
{
    
int caseNum,i;
    
string strTmp;
    
while (cin>>caseNum)
    
{
        
for (i=0;i<caseNum;++i)
        
{
            cin
>>strTmp;
            doProcess(strTmp);
        }

    }

    
return 0;
}

posted on 2008-01-04 22:56  Phinecos(洞庭散人)  阅读(832)  评论(1编辑  收藏  举报

导航