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. [学习总结] python语言学习总结 (三)

    函数闭包 定义 延伸了作用域的函数(能访问定义体之外定义的非全局变量 作用 共享变量的时候避免使用了不安全的全局变量 允许将函数与某些数据关联起来,类似于简化版面向对象编程 相同代码每次生成的闭包,其 ...

  2. thinkphp 为什么访问路径错误,还可以访问

    在学习中访问入口文件,实际上应该访问public\index\index\   但其实也可以访问application.admin.controller\index,同样可以在网页下显示 原理:pub ...

  3. Python SciPy Sparse模块学习笔记

    1. sparse模块的官方document地址:http://docs.scipy.org/doc/scipy/reference/sparse.html   2. sparse matrix的存储 ...

  4. 01_4_SERVLET声明周期

    01_4_SERVLET声明周期 1. Servlet的生命周期 生命全过程 加载ClassLoader 实例化 new //客户端第一次请求的时候,只new一次 初始化init(ServletCon ...

  5. skynet 学习笔记-sproto模块(2)

    云风在skynet中继承了sproto的传输协议,对比protobuf的好处是,能明文看到传输内容,而且skynet不需要protobuf这么功能,所以云风也建议在lua层使用sproto来作为sky ...

  6. iOS应用架构谈part3 网络层设计方案

    前言 网络层在一个App中也是一个不可缺少的部分,工程师们在网络层能够发挥的空间也比较大.另外,苹果对网络请求部分已经做了很好的封装,业界的AFNetworking也被广泛使用.其它的ASIHttpR ...

  7. Typescript学习(一)----准备篇(vscode编译ts文件)

    什么是typescript? typescript是微软开发的一个脚本语言.他是JavaScript的超级,他遵循es6语法规范,他扩展了JavaScript的语法. 理解es5,es6,javasc ...

  8. java版RSA工具类

    /** * RSA算法加密/解密工具类 */ public class RSAUtils { private static final Logger LOGGER = LoggerFactory.ge ...

  9. Python3 简单封装 sqlite3 - SimpleToolSql

    #coding: utf-8 #Author:boxker #Mail:icjb@foxmail.com import sqlite3 import os class simpleToolSql(): ...

  10. 日志切割logrotate和定时任务crontab详解

    1.关于日志切割 日志文件包含了关于系统中发生的事件的有用信息,在排障过程中或者系统性能分析时经常被用到.对于忙碌的服务器,日志文件大小会增长极快,服务器会很快消耗磁盘空间,这成了个问题.除此之外,处 ...