Encoding

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

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
 
Author
ZHANG Zheng
 
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
#include<sstream>
#include<queue>
#include<cmath>
#include<list>
#include<vector>
#include<string>
using namespace std;
#define long long ll
const double PI = acos(-1.0);
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int N = ;
int n, m, tot;
int a[N]; map<string,int> mp;
int main()
{
int t;
cin >> t;
string s;
while(t--)
{
int c = ;
cin >> s;
for(int i=; i<s.size(); i++)
{
if(s[i+]==s[i]){
c++;
}
else{
if(c==){
printf("%c",s[i]);
c = ;
}
else{
printf("%d%c",c,s[i]);
c = ;
}
} }
cout<<endl;
}
}

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 1231 最大连续子序列 --- 入门DP

    HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...

  6. HDU 1231.最大连续子序列-dp+位置标记

    最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  7. HDU 1020(连续同字符统计 **)

    题意是要统计在一段字符串中连续相同的字符,不用再排序,相等但不连续的字符要分开输出,不用合在一起,之前用了桶排序的方法一直 wa,想复杂了. 代码如下: #include <bits/stdc+ ...

  8. DP专题训练之HDU 1231 最大连续子序列

    Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j < ...

  9. HDU 1231 最大连续子序列 &&HDU 1003Max Sum (区间dp问题)

    C - 最大连续子序列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

随机推荐

  1. BFS:胜利大逃亡

    解题心得: 1.水题,主要主意好一个点就好. 2.注意x.y.z坐标的选取就好. 题目: Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城 ...

  2. 1 django

    1.MVC 大部分开发语言中都有MVC框架 MVC框架的核心思想是:解耦 降低各功能模块之间的耦合性,方便变更,更容易重构代码,最大程度上实现代码的重用 m表示model,主要用于对数据库层的封装 v ...

  3. POJ 2771 Guardian of Decency (二分图最大点独立集)

    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6133   Accepted: 25 ...

  4. P3805 【模版】manacher算法(manacher)

    P3805 [模版]manacher算法 题目描述 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 字符串长度为n 输入输出格式 输入格式: 一行小写英文字符a ...

  5. Redis实现之复制(一)

    复制 在Redis中,用户可以通过执行SLAVEOF命令或者设置slaveof选项,让一个服务器去复制(replicate)另一个服务器,我们称呼被复制的服务器为主服务器(master),而对主服务器 ...

  6. 分布式存储系统可靠性系列五:副本放置算法 & CopySet Replication

    本文来自网易云社区 作者:孙建良 在分布式存储系统 中说明了,在一定情况下,copyset的数量不是越多越好,在恢复时间确定的情况下,找到合适的copyset的数量可以降低数据丢失的概率. 在分布式存 ...

  7. Python爬虫作业

    题目如下:   请分析作业页面(https://edu.cnblogs.com/campus/hbu/Python2018Fall/homework/2420),    爬取已提交作业信息,并生成已提 ...

  8. scp -v 查看具体的过程

    前几天跟同事讨论scp 多个文件和 scp多个文件夹的压缩包那个快. 老大说,压缩包快,压缩包传输可以避免每个文件的重建连接,不过文件系统的遍历.目录创建.检验会有一些开销. 他建议我scp -v看下 ...

  9. DOM的相关概念

    [前面的话]DOM全称是Document Object Model,即文档对象模型.我们常说的html文档其实就是一个DOM树,DOM操作就是在内存中找到DOM树上我们想要的DOM对象,对它的属性进行 ...

  10. xstream+dom4j比较对象

      package com.brmoney.util.obj2xml; import java.util.Iterator; import java.util.List; import org.dom ...