天天看点

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;

本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2008/01/04/1026564.html,如需转载请自行联系原作者