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. redis 基本类型

    1 hashes 类型及操作 redis hash 是一个string 类型的 field 和 value 的映射表.他的添加.删除操作时间复杂度都是 O(1) 2 hset,设置 hash fiel ...

  2. java Webservice(一)HttpClient远程调用

    我们将Web Service发布在Tomcat或者其他应用服务器上后,有很多方法可以调用该Web Service,常用的有两种: 1.通过浏览器HTTP调用,返回规范的XML文件内容      2.通 ...

  3. VS中一些不常用的快捷键

    Ctrl+E,S:将空格以···显示,将tab以→显示 在VS中使用快捷键(Ctrl+E,S),所有代码中的空格都会用小点表示出来,然后...删....不想看就再用一次好了... Ctrl+M,L:快 ...

  4. SGMII 和 Serdes 的详细说明

    Serdes  : SERDES是英文SERializer(串行器)/DESerializer(解串器)的简称.它是一种时分多路复用(TDM).点对点的通信技术,即在发送端多路低速并行信号被转换成高速 ...

  5. [svc]磁盘接口与RAID

    一 磁盘接口 IDE 传统家用: /dev/hda1 SISC 传统服务器: /dev/sdb1 SATA 现在家用 SAS 现在服务器用 FC(光纤通道) 高级服务器 注意: 分区编号,1-4只能给 ...

  6. 基于Harbor和CephFS搭建高可用Private Registry

    我们有给客户搭建私有容器仓库的需求.开源的私有容器registry可供选择的不多,除了docker官方的distribution之外,比较知名的是VMware China出品的Harbor,我们选择了 ...

  7. nyoj576 集齐卡片赢大奖(一)

    集齐卡片赢大奖(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 小时候你一定曾经为收集一套三国人物的卡片而买过不少零食吧?这些小吃的袋子里一般都会有一张卡片,如 ...

  8. 快速写excel的方法

    对于用com组件写excel,笔者表示那个太慢了.而且很耗资源,还要装excel. 今天我们就用写文本文件的方式来写excel. 步骤1,用excel写好一个设计一个我们想要的模板. 步骤2,我们把做 ...

  9. 解决Xshell中文乱码问题

    文件====>属性==>中断===>编码===>选择utf8编码

  10. java 多线程11:volatile关键字

    直接先举一个例子普通的线程实例变量的非可见性: public class MyThread28 extends Thread { private boolean isRunning = true; p ...