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. sublime快捷键收藏

    快速查找(ctrl + P)输入@+函数名可以快速找到函数.输入#+文本可以快速进行文件内文本匹配.3. 多行游标功能(ctrl + D,非常实用)如何将文件中的某个单词更改为另一个?方法一:利用查找 ...

  2. Python学习笔记(1)——数组差集

    面试的时候被问到这样一个问题:有A.B两个数组,找出B中有A中没有的所有元素(换言之即是求差集B-A).当时比较紧张,用了最原始的双重嵌套循环逐个比较,很显然这种时间复杂度高达O(n2)的算法相当lo ...

  3. PAT 1059. Prime Factors (25) 质因子分解

    题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...

  4. visual studio 2008安装报错问题处理

    今天刚入职,安装visual studio 2008时报错说web创建组件安装错误,后来发现是因为之前这电脑安装visual studio 2008的时候是office2007刚安装的版本,可是后来系 ...

  5. KEIL C51中const和code的使用

    code是KEIL C51 扩展的关键字,用code修饰的变量将会被放到CODE区里.但C语里的const关键字好像也有定义不能改变的变量的功能,这两个关键字有什么区别呢?在帮助手册里查找const, ...

  6. WPF笔记(1.1 WPF基础)——Hello,WPF!

    原文:WPF笔记(1.1 WPF基础)--Hello,WPF! Example 1-1. Minimal C# WPF application// MyApp.csusing System;using ...

  7. 使用achartengine实现自定义折线图 ----附代码 调试OK

    achartengine作为android开发中最常用的实现图标的开源框架,使用比较方便,参考官方文档谢了如下Demo,实现了自定义折线图. package edu.ustb.chart; impor ...

  8. 【转】Android C程序也可自己手动用交叉编译器编译 (

    原文网址:http://blog.sina.com.cn/s/blog_533074eb0101ez5q.html Android 编译环境 本身比较复杂,且不像普通的编译环境:只有顶层目录下才有 M ...

  9. LeeCode-Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  10. 杭电 3887 Counting Offspring

    根据上篇翻译的文章以及很多个帖子,都讲述了树状数组最基本的功能就是tree[i]保存的是位置i左边小于等于a[i]的数的个数. 这样也就可以解释代码中为什么有f[i]=getsum(sd[i-1])- ...