hdu 1020

//自信满满地交上去~~but。。。超时了

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

int main()
{
    char ch[120],c;
    int i,k,j;
    cin>>i;
    while(i)
    {
        cin>>ch;
        for(k=0;k<strlen(ch);)
        {
            if(ch[k]!=ch[k+1])
            {cout<<ch[k];k++;}
            else
            {
                c=ch[k];
                for(j=k;ch[k]&&ch[j]==c;j++);
                cout<<j-k<<c;
                k=j;
            }
        }
        cout<<endl;
        i--;
    }
    return 0;
}

//于是。。。重来。。。orz
//这是借鉴大神的。。。。发现自己的思路好单一。。。。。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n,i,cnt;
    char str[10005];
    cin >> n;
    while(n--)
    {
        cin >> str;
        for(i = 0; str[i]!='\0';)
        {
            cnt = 1;
            while(str[i] == str[i+1])
            {
                cnt++;
                i++;
            }
            if(cnt == 1)
            cout << str[i];
            else
            cout << cnt << str[i];
            i++;
        }
        cout << endl;
    }

    return 0;
}

 

posted @ 2016-02-18 16:13  邻家那小孩儿  阅读(212)  评论(0编辑  收藏  举报