首页 > 其他 > 详细

hdu 1020

时间:2016-02-18 17:51:43      阅读:237      评论:0      收藏:0      [点我收藏+]

//自信满满地交上去~~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;
}

 

hdu 1020

原文:http://www.cnblogs.com/nefu929831238/p/5198526.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!