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()
{
char a[];
int n;
scanf("%d",&n);
getchar();
while(n--)
{
memset(a,,sizeof(a));
gets(a);
int len=strlen(a),i,count=;
for(i=;i<len-;i++)
{
if(a[i]==a[i+])
{
count++;
if(i==len-)
printf("%d%c",count,a[i]);
}
else
{
if(i==len-)
{
if(count==)
printf("%c%c",a[i],a[i+]);
else
printf("%d%c%c",count,a[i],a[i+]);
}
else
{
if(count==)
printf("%c",a[i]);
else
printf("%d%c",count,a[i]);
}
count=;
}
}
printf("\n");
}
}

encoding(hdoj1020)的更多相关文章

  1. 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)

    //1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...

  2. SVN遇到Can't convert string from 'UTF-8' to native encoding(转)

    svn: Can't convert string from 'UTF-8' to native encoding: svn: platform/console-framework/portal/im ...

  3. 1008. Image Encoding(bfs)

    1008 没营养的破题 #include <iostream> #include<cstdio> #include<cstring> #include<alg ...

  4. Redis之(二)数据类型及存储结构

    Redis支持五中数据类型:String(字符串),Hash(哈希),List(列表),Set(集合)及zset(sortedset:有序集合). Redis定义了丰富的原语命令,可以直接与Redis ...

  5. 初学Java Web(2)——搭建Java Web开发环境

    虽然说 html 和 css 等前端技术,是对于 Web 来说不可或缺的技术,但是毕竟更为简单一些,所以就不详细介绍了,没有基础的同学可以去菜鸟教程或者W3school进行自主学习,最好的方式还是做一 ...

  6. Spring Boot属性文件配置文档(全部)

    This sample file is meant as a guide only. Do not copy/paste the entire content into your applicatio ...

  7. Struts2学习(1)

    struts2概述 1.struts2框架应用javaee三层结构中web层框架. 2.strut2框架在struts1和webwork基础之上发展全新的框架. 3.struts2解决的问题: 4.版 ...

  8. Java自动化测试框架-04 - 来给你的测试报告化个妆整个形 - (上)(详细教程)

    简介 前边通过宏哥的讲解和分享想必小伙伴们和童鞋们都已经见过testng框架生成的测试报告,是不是它的样子和长相实在是不敢让大家伙恭维.那么今天宏哥就当一回美容师,由宏哥来给它美美容:当一回外科医生, ...

  9. Scrapy进阶知识点总结(一)——基本命令与基本类(spider,request,response)

    一.常见命令 scrapy全局命令可以在任何地方用,项目命令只能在项目路径下用 全局命令: 项目命令: startproject crawl genspider check settings list ...

随机推荐

  1. Zend Studio 文件头和方法注释设置

    在zend studio中选择窗口->首选项->PHP–>编辑器 –>模板 –>新建 然后添加 funinfo或fileinfo 模板代码根据下边定义的COPY过去就可以 ...

  2. ajax请求解析springmvc返回的json数据

    需要使用的框架 spring3.0 jquery1.9.0(简化ajax开发的js库) Jackson(json处理器):jackson-core-asl-1.9.2.jar,jackson-mapp ...

  3. Effective Java2读书笔记-创建和销毁对象(二)

    第3条:用私有构造器或者枚举类型强化Singleton属性 这一条,总体来说,就是讲了一个小技巧,将构造器声明为private,可以实现单例.具体有以下几种实现的方式. ①最传统的单例实现模式,可能有 ...

  4. Oracle 唯一主键引发的行锁

    SQL> create table test(id int PRIMARY KEY, name char(10)); 表已创建. Session 1: SQL> select * from ...

  5. XML文档形式&JAVA抽象类和接口的区别&拦截器过滤器区别

    XML文档定义有几种形式?它们之间有何本质区别?解析XML文档有哪几种方式? a: 两种形式 dtd schemab: 本质区别:schema本身是xml的,可以被XML解析器解析(这也是从DTD上发 ...

  6. json中换行问题

    json中不能存在换行,但可以进行替换后给服务器 function(text_info) { text_info=text_info.replace(/\r/gm,"<br\>& ...

  7. 中国版 Ubuntu Kylin 14.04 LTS 麒麟操作系统中文版发布下载 (Ubuntu天朝定制版)

    中国版 Ubuntu Kylin 14.04 LTS 麒麟操作系统中文版发布下载 (Ubuntu天朝定制版) http://www.iplaysoft.com/ubuntukylin.html

  8. Peeking Iterator 解答

    Question Given an Iterator class interface with methods: next() and hasNext(), design and implement ...

  9. 怎样使用LaTeX输入葡萄牙语等语言中的特殊字符

    论文中引用了大名鼎鼎ER random graph model,但是这两位的名字不太好打,发现Google Scholar中直接下载的bib文件中也是错的.找了一会,发现转义字符已经定义得很好了.只是 ...

  10. Android技术路线图

    邮件问题: 老师你好,我从去年就在看你的关于Android的视频了,的确讲的不错,去年看了一段时间,寒假的时候回家重新复习了一下Java基础知识,开学的时候看到你又陆续出了一些视频,这段时间看完了,跟 ...