hdu1020 Encoding

/*
		Author:snowflake
		Time:2012/5/13
		Desc:Water
*/
/*
题目大意:统计相等连续字母个数,1个直接输出,>=2输出个数加上一个字符
15ms的代码,很容易懂。。 就是逐位比较 
*/

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

int main()
{
	int n;
	char str[10005];
	int num, i, j;
	cin >> n;
	while(n--)
	{
		scanf("%s",&str);
		int a = 1;//循环增量指针 
		for(i = 0; i < strlen(str); i += a)
		{
			//这两个注意回溯 
			num = 1;
			a = 1;
			for(j = i + 1; j < strlen(str); j++)
			{
				//判断 
				if(str[i] == str[j])
				{
					num++;
					a++;//下一次循环从加a的地方开始	
				}	
				else
					break;	
			}
			if(num == 1)
				printf("%c",str[i]);
			else
				printf("%d%c",num,str[i]);
		}
		printf("\n");
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值