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. 【2015年最新App Store退款流程详解】最详细AppStore退款流程图文教程

    本帖最后由 想吐就吐出来 于 2015-7-1 14:25 编辑 如果你一不小心买错了iOS软件,从App Store上下载了游戏或软件后悔了,那怎么办?可以退款吗?答案是可以的!苹果这点还是很人性化 ...

  2. VirtualBox的四种网络连接方式详解

    VirtualBox中有4中网络连接方式: 1. NAT 2. Bridged Adapter 3. Internal 4. Host-only Adapter VMWare中有三种,其实他跟VMWa ...

  3. Android 颜色配置表-颜色类

    android开发中,常常会用到color.xml颜色配置,好的颜色配置可以让尼的应用让人看起来赏心悦目! 不罗嗦,上图先 该工程已经罗列了常用的颜色配置 附上工程链接:http://download ...

  4. 执行一条cmd命令的window.bat 批处理代码:

    . .执行一条cmd命令的window.bat 批处理代码: @echo off echo NodeJS SUPERVISOR...Server.js ::下面是批处理代码 supervisor d: ...

  5. JavaScript高级程序设计38.pdf

    比较DOM范围 在有多个范围的情况下,可以使用compareBoundaryPoints()方法来确认这些范围是否有公共的边界,接收两个参数:表示比较方式的常量值和要比较的范围 常量如下 Range. ...

  6. [Android Framework]linux 文件系统

    目录名   bin 用户二进制工具 boot Linux内核镜像文件, 由bootloader程序读取并装载 dev 各种系统硬件设备 etc 系统配置文件及其他配置文件 home 用户工作目录 li ...

  7. 搜索算法:深度优先搜索(DFS)

    关于深搜的介绍,在网上有很多,不再赘述.主要以题目形式实例讲解. POJ - 1321 (http://poj.org/problem?id=1321) 题目大意:给出一个棋盘,棋子不能同行同列,求放 ...

  8. mysql常用的一些命令,用于查看数据库、表、字段编码

    1.查看数据库支持的所有字符集         show character set;或show char set; 2.查看当前状态 里面包括当然的字符集设置         status或者\s ...

  9. 一个空格引发的bug

    好久没写博客了. 我们的一个项目用的thinkphp框架,当在debug模式下面运行很正常,但切换到生产模式时,刷新页面第一次可以正常显示,刷新第二次会出现错误如下: Fatal error: Cal ...

  10. 【python自动化第四篇:python入门进阶】

    今天的课程总结: 装饰器 迭代器&生成器 json&pickle实现数据的序列化 软件目录结构规范 一.装饰器 装饰器的本质是函数,起目的就是用来为其它函数增加附加功能 原则:不能修改 ...