Encoding

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 <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
#define INF 100000
typedef long long ll;
const int maxn=;
char s[maxn];
int main()
{
int n;
scanf("%d",&n);
while(n--){
scanf("%s",s);
int temp=;
for(int i=;i<=strlen(s);i++){
if(s[i]==s[i-]) temp++;
else{
if(temp==) printf("%c",s[i-]);
else printf("%d%c",temp,s[i-]);
temp=;
}
}
printf("\n");
}
return ;
}

HDU-1020(水题)的更多相关文章

  1. HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  2. HDU 5391 水题。

    E - 5 Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. hdu 1544 水题

    水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...

  4. HDU排序水题

    1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...

  5. hdu 2710 水题

    题意:判断一些数里有最大因子的数 水题,省赛即将临近,高效的代码风格需要养成,为了简化代码,以后可能会更多的使用宏定义,但是通常也只是快速拿下第一道水题,涨自信.大部分的代码还是普通的形式,实际上能简 ...

  6. Dijkstra算法---HDU 2544 水题(模板)

    /* 对于只会弗洛伊德的我,迪杰斯特拉有点不是很理解,后来发现这主要用于单源最短路,稍稍明白了点,不过还是很菜,这里只是用了邻接矩阵 套模板,对于邻接表暂时还,,,没做题,后续再更新.现将这题贴上,应 ...

  7. hdu 5162(水题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5162 题解:看了半天以为测试用例写错了.这题玩文字游戏.它问的是当前第i名是原数组中的第几个. #i ...

  8. hdu 3357 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...

  9. hdu 5038 水题 可是题意坑

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数  这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心  If not all ...

  10. hdu 5166(水题)

    Missing number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. 学会使用git

    廖雪峰Git教程 这个教程较为简单,循序渐进 易百Git教程 较为系统 在线代码格式化 可以下载全球最大视频网站的视频支持搜索 点这里

  2. C++类的大小

    C++类的大小   一个空类class A{};的大小为什么是1,因为如果不是1,当定义这个类的对象数组时候A objects[5]; objects[0]和objects[1]就在同一个地址处,就无 ...

  3. 【转】Notepad++插件NppProject发布

    原文网址:http://darkbull.net/article/NppProject/ 如果notepad++安装在 系统盘/program files/ 目录下,可能会提示错误.将npp移到其他目 ...

  4. Ignatius and the Princess IV

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  5. LRU 缓冲池 (不考虑多线程)

    lru:(转)LRU算法的实现 什么是LRU算法? LRU是Least Recently Used的缩写,即最近最少使用页面置换算法,是为虚拟页式存储管理服务的.关于操作系统的内存管理,如何节省利用容 ...

  6. leetcode 二分查找

    https://oj.leetcode.com/problems/search-for-a-range/就是一个二分查找,没事练练手 public class Solution { public in ...

  7. Oracle 行拼接 wmsys.wm_concat扩展

    将多行数据拼接成一行: --wmsys.wm_concat group by a.flowid; 但有大小限制:字符串缓冲区太小,超过varchar 4000长度.扩展:更改返回类型为clob --T ...

  8. DevExpress的JavaScript脚本智能提示

    http://www.cnblogs.com/zhaozhan/archive/2011/06/08/2075767.html ASPxScriptIntelliSense.js在安装目录下的Comp ...

  9. HW4.25

    public class Solution { public static void main(String[] args) { double sum; for(int i = 10000; i &l ...

  10. HW4.13

    public class Solution { public static void main(String[] args) { int n = 0; while(n * n * n < 120 ...