天天看點

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,如需轉載請自行聯系原作者