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. java与java学习路线

    JAVA学习路线图 Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征.Java语言作为静态面 ...

  2. Java中的static关键字的用法

    1.静态方法 static:通常在一个类中定义一个方法为static,那就是说,无需本类的对象即可调用此方法 声明为static的方法有以下几条限制: (1)它们仅能调用其他的static方法. (2 ...

  3. Android开发5——文件读写

    一.基本概念 在Android应用中保存文件,保存的位置有两处 ①手机自带的存储空间,较小(如200M),适合保存一些小文件,Android中保存位置在data/data/应用包名/files目录 ② ...

  4. Qt Quick + OpenGL + Bullet初次測试

    Qt Quick + OpenGL + Bullet初次測试 眼下Qt的Quick模块已经表现得很出色,并且可以预留接口来渲染OpenGL场景.一般来说,已经可以满足大部分编程须要了.这次呢.尝试使用 ...

  5. GCC中文错误提示

    最近在教人学c语言,英语不过关,想把ubuntu16.04的gcc改为中文提示,经查找后发现:目前(2016.8.5)基于gcc5.4版本的中文帮助好像还没有. 后来又仔细查找,现在最新的有中文的也就 ...

  6. [svc][op]关闭linux centos各种声音

    现在基本都用xshell了,直接xshell禁止即可 shell报警 #vi /etc/inputrc ================================ set bell-style ...

  7. JVM Inline

    http://www.ssw.uni-linz.ac.at/Research/Papers/Wimmer08PhD/Wimmer08PhD.pdf http://www.azulsystems.com ...

  8. Rewrite MSIL Code on the Fly with the .NET Framework Profiling API

    http://clrprofiler.codeplex.com/ http://blogs.msdn.com/b/davbr/archive/2012/11/19/clrprofiler-4-5-re ...

  9. angular学习笔记(九)-css类和样式3

    再来看一个选择li列表的例子: 点击li中的任意项,被点击的li高亮显示: <!DOCTYPE html> <html ng-app> <head> <tit ...

  10. windows 简单api应用

    //调用系统函数 将鼠标移动到相应位置 [DllImport("user32.dll", EntryPoint = "SetCursorPos")] publi ...