1.题目:

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.

InputThe 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.

OutputFor each test case, output the encoded string in a line.

Sample Input

2
ABC
ABBCCC

Sample Output

ABC
A2B3C 2.代码:
//本题使用G++编译
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int sum=;
string a;//定义字符数组
cin>>a;//输入字符数组内容
for(int i=;i<a.length();i++){
if(a[i]==a[i+])
sum++;//若相邻两个字符相同则sum+1
else//若相邻字符不相同则进行else
{
if(sum!=)//若sum!=1,即相邻字符相同则输出sum再输出字符
cout<<sum<<a[i];
else//若相邻字符不相同则直接输出字符
cout<<a[i];
sum=;
}
}
cout<<endl;
}
}

3.总结:

应用了map算法!!!

map初步(由ABBC--->A2BC)的更多相关文章

  1. js map()初步学习

    //array.map(callback,thisObject?),callback需要有return值 //map:'映射' 被映射成新的数组  eg1: let data = [3,4,2]; l ...

  2. Scala实战高手****第8课:零基础实战Scala最常用数据结构Map和Tuple及Spark源码鉴赏

    本课内容1.Map和Tuple在Spark源码中的鉴赏2.Map和Tuple代码操作实战 ------------------------------------------------------- ...

  3. 房产地图google map的初步应用点滴.4)(转)

    房产地图google map的初步应用点滴.1) 房产地图google map的初步应用点滴.2) 房产地图google map的初步应用点滴.3) 房产地图google map的初步应用点滴.4) ...

  4. 房产地图google map的初步应用点滴.3)(转)

    房产地图google map的初步应用点滴.1)房产地图google map的初步应用点滴.2)房产地图google map的初步应用点滴.3) 房产地图google map的初步应用点滴.4) go ...

  5. 房产地图google map的初步应用点滴.2)(转)

    房产地图google map的初步应用点滴.1)房产地图google map的初步应用点滴.2)房产地图google map的初步应用点滴.3) 房产地图google map的初步应用点滴.4) 本来 ...

  6. 房产地图google map的初步应用点滴.1)(转)

    房产地图google map的初步应用点滴.1)房产地图google map的初步应用点滴.2)房产地图google map的初步应用点滴.3) 房产地图google map的初步应用点滴.4) 以前 ...

  7. 对Link Map File的初步认识

    什么是Link Map File Link Map File中文直译为链接映射文件,它是在Xcode生成可执行文件的同时生成的链接信息文件,用于描述可执行文件的构造部分,包括了代码段和数据段的分布情况 ...

  8. 【STL初步】不定长数组:vector + 集合:set + 映射:map

    一.vector 为了节省空间,有时我们会使用动态数组vector. 定义动态数组 vector<类型名>变量名 vector<int>que //定义que为一个int类型的 ...

  9. GO Map的初步使用

    一.集合(Map) 1.1 什么是Map 张三:13910101201 李四:13801010134 map是Go中的内置类型,它将一个值与一个键关联起来.可以使用相应的键检索值. Map 是一种无序 ...

随机推荐

  1. Unity 自定义"=="操作符 [翻译来源blogs.unity3d,2014/05]

    主要内容来源 https://blogs.unity3d.com/cn/2014/05/16/custom-operator-should-we-keep-it/ 在我们代码里,如果有这样的代码: i ...

  2. JS 知识图

  3. AngularJS入门教程之与服务器(Ajax)交互操作示例

    AngularJS从Web服务器请求资源都是通过Ajax来完成,所有的操作封装在$http服务中,$http服务是只能接收一个参数的函数,这个参数是一个对象,用来完成HTTP请求的一些配置,函数返回一 ...

  4. string+DP leetcode-4.最长回文子串

    5. Longest Palindromic Substring 题面 Given a string s, find the longest palindromic substring in s. Y ...

  5. 2.Buffer 缓冲区

    /*缓冲区(Buffer)*/ Buffer 就像一个数组,可以保存多个相同类型的数据.根据数据类型不同(boolean 除外),有以下Buffer常用子类: /*ByteBuffer*/(常用) . ...

  6. eclipse导入项目后出现红色叉号的解决方案

    对于一名程序员来说,我导入的项目在项目的名称上无端加了一个红色的叉号,虽然这个不友好的符号,对于我整个的项目运行没有任何影响,但是总让我觉得不舒服,大大的叉号写在我的项目的脑袋上,我心里能舒服吗?于是 ...

  7. Image Processing and Analysis_8_Edge Detection:Edge and line oriented contour detection State of the art ——2011

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  8. c# 类成员的可访问性

  9. spark not serializable异常分析及解决方案

    转载自: http://bigdataer.net/?p=569 1.背景 在使用spark开发分布式数据计算作业过程中或多或少会遇到如下的错误: Serialization stack: objec ...

  10. cmake升级3.6

    https://blog.csdn.net/u013714645/article/details/77002555 ./boostrap gmake gmake install