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. django1.8读书笔记模型高级进阶

    一.访问外键和多对多值 例如:模型类定义如下 from django.db import models class Publisher(models.Model): name = models.Cha ...

  2. 深入理解 Session 与 Cookie

    Session 与 Cookie 的作用都是为了保持访问用户与后端服务器的交互状态.它们有各自的优点,也有各自的缺陷,然而具有讽刺意味的是它们的优点和它们的使用场景又是矛盾的.例如,使用 Cookie ...

  3. unity, multi pass shader中的surface pass

    今天尝试写一个multi pass shader,但其中有一个Pass是surface pass,总是莫名奇妙地报错.后来看到下面帖子: http://forum.unity3d.com/thread ...

  4. Kafka剖析:Kafka背景及架构介绍

    <Kafka剖析:Kafka背景及架构介绍> <Kafka设计解析:Kafka High Availability(上)> <Kafka设计解析:Kafka High A ...

  5. Qt 自学QGraphicsItem要点 积累

    1.在创建QGraphicsItem子类的时候,想要实现自己绘图,一般是重新实现boundingRect()和paint()函数,如果不重新实现shape(),基类的实现将会退而使用 bounding ...

  6. Oracle 每五千条执行一次的sql语句

    今天碰到一个问题,更新历史数据时,由于数据库表数据量太大,单行更新速度很慢,要求每五千条执行一次提交进行更新.执行SQL如下: declare i_count int; i_large int; be ...

  7. mac下为什么光标按方向键只能一个字一个字地蹦

    系统偏好设置-键盘 把按键重复拉到最快,重复前延迟拉到最短

  8. 利用Django中的url方法实现地址动态拼接自动生成超链接地址

    目标 建立一个图书列表页面,显示图书名列表,并实现点击书名跳转到图书详细页面,显示图书详细信息. URL方法简介 功能:返回一个绝对路径的引用(不包含域名的URL):该引用匹配一个给定的视图函数和 一 ...

  9. 【DSP】CCS中.dat文件的格式

    转自“http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/168292” Here is the infor ...

  10. vs2010程序运行出错 link : fatal error lnk1123: 转换到 coff 期间失败: 文件无效或损坏

    vs2010程序运行出错 link : fatal error lnk1123: 转换到 coff 期间失败: 文件无效或损坏 2014-03-27 11:34杜_柏 | 浏览 36144 次 请问这 ...