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. Ajax学习---Ajax基础学习 180128

    AJAX AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步Javascript和XML”.即使用Javascript语言与服务器进行异步交互,传输的数据为 ...

  2. Kinaba 简单画图

    此片文章简单介绍如何在kinaba 上画图. 如果你,还没有搭建ELK 请参考:ELK日志分析平台搭建全过程 本文参考:http://www.cnblogs.com/hanyifeng/p/58607 ...

  3. 微软Charting图表控件 System.Web.UI.DataVisuliztion.Charting

    一.概述 基于.NET Framework 3.5 SP1的图表控件--Chart,可在WinForm和WebForm下使用!需要引入System.Web.DataVisualization.dll ...

  4. codeforces 1000F One Occurrence(线段树、想法)

    codeforces 1000F One Occurrence 题意 多次询问lr之间只出现过一次的数是多少. 题解 将查询按照左端点排序,对于所有值维护它在当前位置后面第二次出现是什么时候,那么查询 ...

  5. Vim常用命令记录

    (本文仅记录了Vim常用的按键功能和操作,用于备忘和查阅.若为Vim小白,建议先通过列出的参考资源获得对Vim更全面的了解.Vi 是几乎所有Linux发行版都支持的文字编辑工具,也是许多Linux下工 ...

  6. 浏览器相关--H5本地存储

    因为项目需要,最近研究了一下HTML5本地存储相关的东西,在这简单的记录一下. 浏览器存储主要包括一下几个部分1. cookie2. localStorage3. sessionStorage4. i ...

  7. 32、SpringBoot-整合Dubbo

    分布式应用 在分布式系统中,国内常用zookeeper+dubbo组合,而Spring Boot推荐使用全栈的Spring, Spring Boot+Spring Cloud. 分布式系统: Zook ...

  8. 6 spark 存储体系 --内存管理

    6.5  memoryMode

  9. css实现等高布局 两栏自适应布局 三栏自适应布局

    等高布局: HTML结构如下: <div class="wrapper"> <div class="box"> <h1>.. ...

  10. PHP过滤

    1.过滤是不是URL(后台过滤) $url = "https://www.baidu.com"; if(!filter_var($url,FILTER_VALIDATE_URL)) ...