Encoding

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

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

前两次做了没感觉,都WA了0.0

第三遍突然有feel了。

代码:

#include<iostream>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main(void)
{
int n;
cin>>n;
while (n--)
{
string str;
cin>>str;
int i,j,len=str.size(),sum=1;
for (i=0; i<len; i++)
{
if(str[i]==str[i+1])
{
sum++;
}
else
{
if(sum==1)
cout<<str[i];
else
cout<<sum<<str[i];
sum=1;
}
}
cout<<endl;
}
return 0;
}

HDU——1020Encoding(水题,string过)的更多相关文章

  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. HDU——1062Text Reverse(水题string::find系列+reverse)

    Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

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

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

  8. hdu 5162(水题)

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

  9. hdu 5038 水题 可是题意坑

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

  10. hdu 5254 水题

    纯暴力就能过的,可是题目描述真心不清楚,我看了好久好久才明白题目啥意思. 为了迅速打完,代码比较冗余. /* * Author : ben */ #include <cstdio> #in ...

随机推荐

  1. UVA 12325 Zombie'sTreasureChest 宝箱 (分类枚举)

    看上去非常像背包的问题,但是体积太大了. 线性规划的知识,枚举附近点就行了,优先选性价比高的, 宝物有两种体积为S0,价值V0,体积S1,价值V1. 枚举分以下几种: 1:枚举拿宝物1的数量,然后尽量 ...

  2. [学习笔记] C++ 历年试题解析(三)--小补充

    小小的补充一下吧,因为李老师又把直招的卷子发出来了.. 题目 1.有指针变量定义及初始化int *p=new int[10];执行delete [] p;操作将结束指针变量p的生命期.(×) 解释:试 ...

  3. java利用SuffixFileFilter统计目录下特定后缀名文件的数目

    /** * 文件处理类 * @author zhangcd * @date 2017年1月3日 */ public class FileUtil { /** * 得到所有后缀的数目 * * @para ...

  4. iOS与JS相互传值与交互

    JavaScriptCore是webkit的一个重要组成部分,主要是对JS进行解析和提供执行环境.iOS7后苹果在iPhone平台推出,极大的方便了我们对js的操作.我们可以脱离webview直接运行 ...

  5. sql where in字符串问题

    在pycharm中执行 select * from value in(1,2); 会提醒: No statement found under the caret. Execute all statem ...

  6. 【模板】有旋Treap

    如题,这是一个模板... #include <algorithm> #include <iostream> #include <cstring> #include ...

  7. python处理excel总结

    工作中,大家经常会使用excel去处理数据以及展示,但是对于部分工作我们可以借助程序帮忙实现,达到高效解决问题的效果,比如将接口返回的json解析并保存结果到excel中,按一定规律处理excel中的 ...

  8. C++输入密码不显示明文

    之前有遇到需求说输入密码不显示明文,但同时会有一些其他问题,暂时没做,如今经过尝试可以实现,但是得先知道要输入的是密码.主要利用的getch()函数的不回显特点.需要注意的是这个函数不是标准函数,而且 ...

  9. CentOS 6 搭建SVN支持httpd和svnserve独立服务器两种模式 以及邮件配置

    Linux下SVN服务器同时支持Apache的http和svnserve独立服务器两种模式且使用相同的访问权限账号 服务器操作系统:CentOS 6.x 1.在服务器上安装配置SVN服务: 2.配置S ...

  10. golang http 中间件

    golang http 中间件 源码链接 golang的http中间件的实现 首先实现一个http的handler接口 type Handler interface { ServeHTTP(Respo ...