Problem Description

Given a string containing only ‘A’ - ‘Z’, we could encode it using the following method:

  1. Each sub-string containing k same characters should be encoded to “kX” where “X” is the only character in this sub-string.

  2. If the length of the sub-string is 1, ‘1’ should be ignored.

Input

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only ‘A’ - ‘Z’ and the length is less than 10000.

Output

For each test case, output the encoded string in a line.

Sample Input

2

ABC

ABBCCC

Sample Output

ABC

A2B3C

简单的字符串题目

需要注意的只有

如果输入:AABBBAAA

输出的是:2A3B3A

而不是:5A3B

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int s,i,j,n,p,m;
char a[100000],temp;
scanf("%d",&s);
while(s--)
{
scanf("%s",a);
n=strlen(a);
temp=a[0];
m=1;
for(i=1;i<=n;i++)
{
p=1;
if(a[i]==temp)
{
m++;
}
if(a[i]!=temp)
{
p=0;
temp=a[i];
}
if(p==0)
{
if(m==1)
printf("%c",a[i-1]);
else
printf("%d%c",m,a[i-1]);
m=1;
}
}
printf("\n");
}
return 0;
}

最新文章

  1. Linq To Entities 及其相关
  2. Python中请使用isinstance()判断变量类型
  3. poj 1741 Tree(点分治)
  4. StoryBoard 设置TabBar SelectImage 和tintColor
  5. [Swust OJ 648]--简单字典(数位dp)
  6. AForge.net 使用之录像拍照功能实现
  7. 【 js 基础 】【 源码学习 】源码设计 (持续更新)
  8. Java的NIO
  9. 对List中每个对象元素按时间顺序排序
  10. 使用XStream是实现XML与Java对象的转换(1)--简介及入门示例
  11. Netty源码—六、tiny、small内存分配
  12. Hibernate实体类注解中如何忽略某些字段的映射
  13. .8-浅析webpack源码之Tapable介绍
  14. HTML中select的option设置selected=&quot;selected&quot;无效的解决方案
  15. Orangegreenworks封装rpgmakermv
  16. Maven下载私服上的jar包
  17. RNA-seq流程需要进化啦!
  18. [视频]K8飞刀 ms15022 office漏洞演示动画
  19. LR中错误代号为27796的一个解决方法
  20. JSON序列化反序列化

热门文章

  1. Android30-Fragment-理解
  2. SQL使用存儲過程訪問不同服務器
  3. hdu 1396 Counting Triangles(递推)
  4. php之工厂模式
  5. Windows phone 之 UserControl的应用
  6. FileStream读写文件流
  7. Linux 防火墙设置,禁止某个ip访问
  8. PHP文件上传与安全
  9. 解决VS2015无法调试dotnet core项目
  10. u-boot子目录Makefile分析