Encoding

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 16   Accepted Submission(s) : 13
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

 
Author
ZHANG Zheng
 
 
#include <stdio.h>
#include <string.h>
int main()
{
char str[10005];
int N,i,j=0,k;
scanf("%d",&N);
getchar(); //吸收换行符
while (N--)
{
memset(str,0,sizeof(str));
// getchar();第一次吸收换行符,后面就吸收第一个字符,错误!
gets(str);
int len=0;
len=strlen(str);
k=1;
for (i=0;i<len;i++)
{
if (str[i+1]==str[i])//数组开的足够大,并且每次都初始化为0,0和字符值不相等
{
k++;
}
else
{
if (k!=1) printf("%d",k);
printf("%c",str[i]);
k=1; //k的值初始化为1
}
} printf("\n");
}
return 0;
}

hdu Encoding的更多相关文章

  1. A - Character Encoding HDU - 6397 - 方程整数解-容斥原理

    A - Character Encoding HDU - 6397 思路 : 隔板法就是在n个元素间的(n-1)个空中插入k-1个板,可以把n个元素分成k组的方法 普通隔板法 求方程 x+y+z=10 ...

  2. Encoding 分类: HDU 2015-06-25 21:56 9人阅读 评论(0) 收藏

    Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  3. HDU 1020 Encoding POJ 3438 Look and Say

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

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

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

  5. HDU 1020:Encoding

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

  6. HDU 1020 Encoding 模拟

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  7. HDU 1020 Encoding【连续的计数器重置】

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. hdu 6397 Character Encoding (生成函数)

    Problem Description In computer science, a character is a letter, a digit, a punctuation mark or som ...

  9. hdu 1020 Encoding

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Given a ...

随机推荐

  1. linux笔记_day12_shell编程

    1.shell中如何进行算术运算 A=1 B=2 1)let 算术运算表达式 let C=$A+$B 2)$[算术运算表达式] C=$[$A+$B] 3)$(($A+$B)) 4) expr 算术表达 ...

  2. MySQL 5.7在线设置复制过滤【转】

    转自 MySQL 5.7在线设置复制过滤 - yayun - 博客园 https://www.cnblogs.com/gomysql/p/4991197.html 5.7也GA了,有许多新的特性,其中 ...

  3. 文字小于12px时,设置line-height不居中问题

    设置了文字了小于12px时,会存在设置了line-height的不生效的问题,主要是由于基线的问题,这篇文章解释的很清楚,有兴趣的可以看下https://blog.csdn.net/q12151634 ...

  4. 【前端vue开发】vue知识点超链接学习笔记

    1.如何去除vue项目中的 # --- History模式: https://www.cnblogs.com/zhuzhenwei918/p/6892066.html 2.三分钟教你写个Vue组件: ...

  5. 浅谈js设计模式之发布 — 订阅模式

    发布 — 订阅模式又叫观察者模式,它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都将得到通知.在 JavaScript开发中,我们一般用事件模型来替代传统的发布 — ...

  6. Java 接口关键字 interface

    interface这个关键字产生一个完全抽象的类,它根本就没有提供任何具体的实现,它允许创建者确定方法名.参数列表和返回类型,但没有任何方法体,接口只提供了形式,而未提供任何具体实现 一个接口表示:& ...

  7. KnockoutJs学习笔记(十一)

    enable binding往往作用于form elements,比如input.select和textarea等.包含enable binding的DOM元素会依照enable binding参数的 ...

  8. .NetCore下使用Autofac做 IOC 容器

    在.NetCore中使用自带的IOC容器 写注入的时候会写很多,如果要自己封装的话也达不到预期的效果,所以这里采用Autofac来时替代 .NetCore自带的容器 nuget首先引用Autofac. ...

  9. SRILM Ngram 折扣平滑算法

    关于n-gram 语言模型,大部分在这篇博客里 记过了,   SRILM 语言模型格式解读 , 其实看完了,ngram的大概用法都比较清楚了, 但是关于平滑算法,一直很模糊,就晓得一个"劫富 ...

  10. 【LOJ】#2269. 「SDOI2017」切树游戏

    题解 把所有的数组一开始就FWT好然后再IFWT回去可以减小常数 从13s跑到0.7s-- 可以参照immortalCO的论文,感受一下毒瘤的动态动态DP 就是用数据结构维护线性递推的矩阵的乘积 由于 ...