Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39047    Accepted Submission(s): 17279

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<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
struct Node
{
char a;
int num;
};
vector<Node> q; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
q.clear();
char ch[];
scanf("%s",ch);
int len=strlen(ch);
Node tmp;
tmp.a=ch[];
tmp.num=;
for(int i=;i<len;i++)
{
if(ch[i]==tmp.a) tmp.num++;
else
{
q.push_back(tmp);
tmp.a=ch[i];
tmp.num=;
}
}
q.push_back(tmp);
for(int i=;i<q.size();i++)
{
if(q[i].num>)
{
printf("%d%c",q[i].num,q[i].a);
}
else printf("%c",q[i].a);
}
printf("\n");
}
return ;
}
 

HDU 1020 Encoding 模拟的更多相关文章

  1. 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 ...

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

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

  3. hdu 1020 Encoding

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

  4. HDU 1020:Encoding

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

  5. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  6. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  7. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  8. HDU 2568[前进]模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...

  9. hdu 4964 恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...

随机推荐

  1. nginx安装和配置

    一.安装:yum install nginx service nginx restart/start/check/status/... 二.配置:官网文档 http://nginx.org/en/do ...

  2. jquery中remove()与detach()的区别

    说到删除节点,马上就会想到remove,不过原来还有一个detach,而且它们还是有区别的,就是detach保留了jquery的数据,而remove就会完全删除干净.所以如果在删除一个dom节点后还想 ...

  3. Storm应用系列之——集成Kafka

    本文系原创系列,转载请注明. 原帖地址:http://blog.csdn.net/xeseo 前言 在前面Storm系列之——基本概念一文中,提到过Storm的Spout应该是源源不断的取数据,不能间 ...

  4. 安装Python3.6.x

    #安装依赖包 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel -y #下载Python3.6.x wget https:/ ...

  5. Razor语法(四)

    1. @代表开始一个Razor代码块,Razor会自动匹配代码中的花括号,比如@if(p.Active){<li>@p.Name</li>} 2. @{code}标识一个Raz ...

  6. Joiner的用法

    Google Guava提供了Joiner类专门用来连接String. 譬如说有个String数组,里面有"a","b","c",我们可以通 ...

  7. Cat安装

    1,windows7+jdk1.7(1.7,1.6都可以,1.8不行)+maven3.3.3 2,到github上下载cat源码 https://github.com/dianping/cat 例如下 ...

  8. 解决Eclipse下不自动拷贝apk到模拟器问题( The connection to adb is down, and a severe error has occured)

    如题 解决方案如下: 1.先把eclipse关闭.2.在管理器转到你的android SDK 的platform-tools下3.键入adb kill-server ,如果adb关闭了会提示 serv ...

  9. 4CIF是什么意思

    QCIF:176X144 CIF:352X288 2CIF:704X288 DCIF:584X384 4CIF:704X576 CIF是常用的标准化图像格式(Common Intermediate F ...

  10. REMOTE HOST IDENTIFICATION HAS CHANGED问题的解决方式

    好久没更新博客园. 这段没更新博客的时间内收获了很多,所以更新下博客来整理.记录这段时间内学到的内容. 最近腾讯云服务器欠费停机了,所以趁着缴费.趁着心血来潮就……重装了云系统.结果在进行远程ssh连 ...