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. opencv中cvCreateImage大图片时出错

    最近在做遥感图像的图像处理工作,使用了 OpenCV2.4.8来处理.遥感图像不同于一般图像的一个大的特点是图片容量超大,轻轻松松就能超过10000x10000个像素点,在OpenCV中使用cvCre ...

  2. mysql中的意向锁IS,IX

    知识储备: 1.官方文档上说mysql是支持非锁定读的:这个功能是这样实现的,如果事务a 要对行的数据进行更新的话,那么事务a要得到行的x锁,并把这一行  之前的样子记录在undo log里面,这样一 ...

  3. basename $0的用法

    basename 从文件名中去掉路径信息, 只打印出文件名. 结构 basename $0 可以让脚本知道它自己的名字, 也就是, 它被调用的名字. 可以用来显示用法信息, 比如如果你调用脚本的时候缺 ...

  4. 在Git中一定要关注的crlf自动转换

    GitHub 第一坑:换行符自动转换 如果你已经做出了错误的选择,也不需要重新安装,可以直接使用命令行来修改设置.很简单,直接打开这货自带的命令行工具 Git Bash,输入以下命令,再敲回车即可: ...

  5. 开源C/C++网络库比较

    在开源的C/C++网络库中, 常用的就那么几个, 在业界知名度最高的, 应该是ACE了, 不过是个重量级的大家伙, 轻量级的有libevent, libev, 还有 Boost的ASIO. ACE是一 ...

  6. Eclipse插件Mylyn管理上下文任务管理

    原文地址:http://www.ibm.com/developerworks/cn/java/j-mylyn1/ Mylyn 2.0,第 1 部分: 集成的任务管理 使用集成的 Eclipse 问题跟 ...

  7. Maximum Depth of Binary Tree 解答

    Question Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...

  8. [Medusa-dev] psp_handler - embed python in HTML like ASP

    [Medusa-dev] psp_handler - embed python in HTML like ASP [Medusa-dev] psp_handler - embed python in ...

  9. 51操作各种demo 驱动

    24C02 bit write=0; //写24C02的标志: sbit sda=P2^0; sbit scl=P2^1; void delay0() { ;; } void start() //开始 ...

  10. python中使用mahotas包实现高斯模糊

    高斯模糊 import mahotas as mh import numpy as np from matplotlib import pyplot as plt image=mh.imread('i ...