pid=1020">Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 25691    Accepted Submission(s): 11289

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<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 10000 + 50;
char str[M];
char a[M];
int b[M]; int main()
{
int n;
int t=0;
int p;
int i;
scanf("%d", &n);
while( n-- )
{
t=0;
p=0;
memset(str, 0, sizeof(str));
scanf("%s", str);
a[t]=str[0];
for(i=0; i<strlen(str); i++)
{
if(str[i]==str[i+1])
p++;
else
{
b[t]=p;
t++;
a[t]=str[i+1];
p=0;
}
}
for(i=0; i<t; i++)
{
if(b[i]>0)
printf("%d%c", b[i]+1, a[i]);
else
printf("%c", a[i]);
} printf("\n");
} return 0;
}

HDU 1020:Encoding的更多相关文章

  1. HDU - 6409:没有兄弟的舞会(数学+思维)

    链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...

  2. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  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. HDU - 6397:Character Encoding (组合数&容斥)

    题意:T组数据,给次给出N,M,K,多少种方案,用[0,N-1]范围的数,表示一个M排列,其和为K: 思路:隔板法,不限制[0,N-1]的时候答案是C(M+K-1,M-1):那么我们减去至少一个> ...

  5. HDU 1020 Encoding 模拟

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

  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

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

  8. HDU 2732:Leapin' Lizards(最大流)

    http://acm.hdu.edu.cn/showproblem.php?pid=2732 题意:给出两个地图,蜥蜴从一个柱子跳跃到另外一个地方,那么这个柱子就可能会坍塌,第一个地图是柱子可以容忍跳 ...

  9. HDU 4289:Control(最小割)

    http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可 ...

随机推荐

  1. Smarty中{literal}的使用详解(ecshop)

    如何在文件里加入JS代码,如果按一般平常添加方法,会出错,解决的方法:把script套在{literal}{/literal}之间试试看,例如:{literal} {/literal} ------- ...

  2. jquery的animate()方法也可设置非css属性

    如题,举例: $('body').animate({scrollTop:0}, 1500); $("body").animate({scrollTop:"-=" ...

  3. TinyXml 操作XML 常用操作

    源代码下载:http://sourceforge.net/projects/tinyxml/files/ 如下是一个XML片段:    <Persons>        <Perso ...

  4. iOS中使用block传值

    转自:http://blog.sina.com.cn/s/blog_60b45f230100yiaf.html 用此方法传值可以替代委托了.具体例子: MainView.h #import <U ...

  5. sudo和man的tab自动补全

    要加入sudo和man的tab自动补全功能,只需在~/.bashrc中加入: #Enabling tab-completioncomplete -cf sudocomplete -cf man

  6. 转载: 8个月从CS菜鸟到拿到Google Offer的经历+内推

    8个月从CS菜鸟到拿到Google Offer的经历+内推 http://blog.csdn.net/fightforyourdream/article/details/17094127 http:/ ...

  7. SQL语句的一些基本使用以及一些技巧

    #SELECT 列名1, 列名2, from 表明 #SELECT id,title,content,type from news 效率相对较高#SELECT * from news *代表所有字段, ...

  8. 【Java】创建线程对象两种方式

    1.继承Thread类,重载run方法: Thread t = new Thread(new Runnable() { @Override public void run() { // TODO Au ...

  9. eclipse egit 解决冲突

    eclipse egit冲突解决 在 pull 代码的时候 ,从远程仓库与本地仓库进行同步的时候  ,如果服务器版本与本地仓库版本不一致, 需要解决冲突 首先需要将改动的代码commit到本地仓库,冲 ...

  10. 【C#/WPF】图像变换的Undo撤销——用Stack命令栈

    需求: 图层中有一张图片,可以对该图层进行平移.缩放.旋转操作,现在要求做Undo撤销功能,使得图层回复上一步操作时的状态. 关于图像的平移.缩放.旋转,可以参考在下的另一篇博客的整理: http:/ ...