[恢]hdu 1020

2011-12-16 07:58:56

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1020

题意:把给的字符串编码,如sample。

代码:

# include <stdio.h>


char str[10010] ;

int calc(char s[])
{
int i, cnt = 0 ;
for (i = 0 ; s[i] ; i++)
{
if (s[i] != s[0]) break ;
cnt++ ;
}
return cnt ;
}

int main ()
{
int T, i, n ;
scanf ("%d*c", &T) ;
while (T--)
{
scanf ("%s", str) ;
for (i = 0 ; str[i] ;i++)
{
n = calc(str+i) ;
if (n == 1) putchar (str[i]) ;
else printf ("%d%c", n, str[i]) ;
i+=n-1 ;
}
printf ("\n") ;
}
return 0 ;
}



posted @ 2012-01-06 17:22  Seraph2012  阅读(143)  评论(0编辑  收藏  举报