您的位置:首页 > 其它

HDU1020

2015-02-05 01:04 169 查看
用这种方法实现的代码好像在哪看过,但忘记了在哪了
/*vector_change----HDU1020*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 1010
#define LL long long
#define debug(x) cout<<#x<<":"<<(x)<<endl;
using namespace std;
//15-2-5
int main()
{
    int n;
    scanf("%d", &n);
    char ch1, ch2;
    int num = 1;
    getchar(); //吸收按回车
    while( n-- )
    {
        ch1 = getchar();
        while( ch2 != '\n' ) //结束条件,遇到回车键
        {
            ch2 = getchar();
            if( ch2 == ch1 ) num++;
            else{
                if(num>1) printf("%d%c", num, ch1);
                else printf("%c", ch1);
                num = 1;
            }
            ch1 = ch2;
        }
        ch2 = '0';  //ch2 会留下上次的'\n'所以要清空
        printf("\n");
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: