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算法!!!

最新文章

  1. jquery选择器(综合)
  2. 控制Wordpress对搜索引擎的可见性
  3. 打包.a 文件时, build phases- Link Binary With Libraries
  4. Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers &quot;public&quot;
  5. Python Tomcat Script(多实例)
  6. mysql 日期 时间戳 转换
  7. hdu 3594 仙人掌图
  8. 设计模式 Template Method模式 显示程序猿的一天
  9. Linux 典型应用之常用命令
  10. [TFS教程]TFS: Get Command
  11. DirectX SDK (June 2010)安装错误S1023,解决方法
  12. 【小程序】页面无法更新tabbar角标属性时
  13. vim改善生活的几个插件
  14. 通过TortoiseSVN进行文件(夹)外链 External File
  15. 踩坑记(1)——使用slf4j+logback记录日志
  16. C# Atomic&lt;T&gt; Generic
  17. Check类中的incl、union,excl,diff,intersect
  18. lua闭包与简易迭代器实现
  19. flex作图
  20. 理解HashSet及使用

热门文章

  1. cli中webpack的配置详解
  2. css-两个div并排,左边宽度固定右边自适应的布局 的实现方法
  3. DAY2新手选品原则及供应商选择
  4. 全排列 递归方法(permutation原理
  5. Sonya and Robots
  6. c++初步认识
  7. Thinkphp 两级联动
  8. 2018/7/31 -zznu-oj -问题 C: 磨刀- 【扩展欧几里得算法的基本应用】
  9. http协议头
  10. Week08_day01 (Hive实现WordCount计数)