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
------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
int main()
{
int N, length, count;
char str[10001];
scanf("%d", &N);
while (N)
{
scanf("%s", str);
length = strlen(str);
count = 1;
for (int i = 1; i <= length; i++)
{
if (str[i] == str[i - 1])
count++;
else
{
if (count == 1)
printf("%c", str[i - 1]);
else
{
printf("%d%c", count, str[i - 1]);
count = 1;
}
}
}
printf("\n");
N--;
}
return 0;
}

  

ACM1020:Encoding的更多相关文章

  1. .NETFramework:Encoding

    ylbtech-.NETFramework:Encoding 1.返回顶部 1. #region 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, Pub ...

  2. HDU 1020:Encoding

    pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  3. 《利用python进行数据分析》读书笔记--第四章 numpy基础:数组和矢量计算

    http://www.cnblogs.com/batteryhp/p/5000104.html 第四章 Numpy基础:数组和矢量计算 第一部分:numpy的ndarray:一种多维数组对象 实话说, ...

  4. Python编码问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(12

    今天安装了PyScripter编辑器,刚要写代码,突然就出现异常: <span style="font-size:14px;color:#ff0000;">>&g ...

  5. 30天C#基础巩固------集合,File(文件操作 ),Encoding处理字符集

    一:泛型    关于泛型我自己也不是很好的理解,但是具体的运用还是可以的,可以这样的理解,我们定义一个数组,但是不知道将来它是保存什么类型的值,很是矛盾,这个时候泛型就出现了,它可以解决这个场景,li ...

  6. Python类的特点 (3) :静态方法与类方法

    Python中的方法有4种: 1)模块中的全局方法,不属于任何类,用"模块名.方法名"形式调用. 2)类中定义的实例方法,也被称为绑定方法(Bound method),这种方法的第 ...

  7. Python类的特点 (2) :类属性与实例属性的关系

    测试代码: #encoding:utf-8 class Parent(object): x=1 #x是Parent类的属性(字段) ls=[1,2] #ls是一个列表,也是Parent类的属性(字段) ...

  8. Python类的特点 (1):构造函数与方法

    Python中,类的特点: #encoding:utf-8 class Parent(object): x=1 #x是Parent类的属性(字段) def __init__(self): print ...

  9. 【20140113-2】MyEclipse生成javadoc时出错:编码GBK的不可映射字符

    今天生成java doc文档时,出现了如下所示的错误: 正在装入软件包 com.wisdom.test 的源文件...F:\workspace\StringUtils\src\com\wisdom\t ...

随机推荐

  1. [翻译] JTSlideShadowAnimation

    JTSlideShadowAnimation 效果图: JTSlideShadowAnimation allow you to reproduce the famous "slide to ...

  2. python错误和异常(1)

    1  SyntaxError: Python解释器语法错误,是唯一不是在运行时发生的异常. 2 检测和处理异常 try语句有两种主要形式:try-except 和 try-finally. 只能二选一 ...

  3. Office 365实现单点登录系列(1)—域环境搭建

    Hello 小伙伴们, 2018新年快乐,作为2018年首篇文章,怎么能不给大家带来点干货呢?这篇文章其实我9月底的时候已经在MSDN上发布过了,为表诚意,我更新了这篇文章,并把它组成了一个系列,2. ...

  4. Mantle 初步使用

    我写了一篇 Mantle 初步使用 的文章,欢迎访问!

  5. POI读取单元格信息及单元格公式

    Java操作EXCEL的利器一般都是POI和JXL,鄙人只是POI的忠实粉丝.(其实我是没有用过JXL). 现在大多数的excel都是07以上的版本,所以我一般是用07的基础上使用POI. 一.读取单 ...

  6. Python安装第三方库 xlrd 和 xlwt 。处理Excel表格

    1. 到   https://pypi.python.org/simple/xlwt/ 和https://pypi.python.org/simple/xlrt/ 下载 xlrd  和  xlwt  ...

  7. 5、Spring Cloud-声明式调用 Feign(下)

    5.5.在Feign中使用HttpClient和OkhHttp Feign 中.Client 是一个非常重要的组件, Feign 最终发送 Request 请求以及接收 Response响应都是由 C ...

  8. Kali-linux绘制网络结构图

    CaseFile工具用来绘制网络结构图.使用该工具能快速添加和连接,并能以图形界面形式灵活的构建网络结构图.本节将介绍Maltego CaseFile的使用. 在使用CaseFile工具之前,需要修改 ...

  9. PAT——1052. 卖个萌

    萌萌哒表情符号通常由“手”.“眼”.“口”三个主要部分组成.简单起见,我们假设一个表情符号是按下列格式输出的: [左手]([左眼][口][右眼])[右手] 现给出可选用的符号集合,请你按用户的要求输出 ...

  10. Dynamic Rankings—带单点修改的主席树

    这道题应该是很不错的板子了\(\mathcal{\color{cyan}{Link}}\) \(\mathcal{\color{red}{Description}}\) 给定一个序列,有两种操作.一是 ...