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+tomca负载均衡

    Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性: 作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 ...

  2. hdu 1244 DP

    水DP dp[i%2][j]=Max(dp[i%2][j-1],dp[1-i%2][j-l[i]]+sum[j]-sum[j-l[i]]); #include "stdio.h" ...

  3. php上传漏洞获root权限

    首先用nmap检测一下目标网站的系统服务和一些端口banner的信息.   Nmap -v -sT -sV -O -P0 -oX test.xml ***.kr   21/tcp   open     ...

  4. ArcGIS Server的切图原理深入【转】

    http://blog.newnaw.com/?p=69 GoogleMap,Virtual Earth,YahooMap等,目前所有的WebGIS都使用了缓存机制以提高地图访问速度.原理都是将地图设 ...

  5. Kolla 4.0.0环境下VIP无法迁移问题排查

    VRRP无法切换VIP的问题分析: Keepalived的配置文件:/etc/kolla/keepalived/keepalived.conf当中,nopreempt选项是影响切换的因素之一,另一个因 ...

  6. seo关键字优化

    SEO 第一: 标题关键字分析 分析和选择行业热门的关键字,并合理的应用于网站标题内及分布到各栏目页面和内页. 其实个人觉得标题.内容.以及与内容相关性链接必须要足.还有就是出现的层次感,例如: a) ...

  7. EditText输入为空button不可点击搜索

    一丶任务详情 二丶改动后演示效果 三丶改动过程 分析:非常明显这里是须要监听EditText,推断输入字符串长度是否不为0来改变Button样式 首先的屡清楚代码逻辑在适当的位子加监听推断是最好的处理 ...

  8. location.href

      location.href用法 CreateTime--2018年2月22日15:22:02 Author:Marydon 1.在当前页面打开URL页面 // 方式一 window.locatio ...

  9. struts 在Action中访问web元素(request,session等)

    出发jsp: <?xml version="1.0" encoding="GB18030" ?> <%@ page language=&quo ...

  10. Drupal与其它开源系统的整合

    网上看到一篇介绍Drupal与phpbb整合的文章.浏览了一下,真心地不错.于是就想将与整合有关的文章做一个汇总,以备不时之需: Drupal7整合PHPBB论坛 Drupal 7 整合 Vanill ...