Encoding

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

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<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
struct Node
{
char a;
int num;
};
vector<Node> q; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
q.clear();
char ch[];
scanf("%s",ch);
int len=strlen(ch);
Node tmp;
tmp.a=ch[];
tmp.num=;
for(int i=;i<len;i++)
{
if(ch[i]==tmp.a) tmp.num++;
else
{
q.push_back(tmp);
tmp.a=ch[i];
tmp.num=;
}
}
q.push_back(tmp);
for(int i=;i<q.size();i++)
{
if(q[i].num>)
{
printf("%d%c",q[i].num,q[i].a);
}
else printf("%c",q[i].a);
}
printf("\n");
}
return ;
}
 

最新文章

  1. tomcat manager配置
  2. SQL Cumulative Sum累积求和
  3. NES模拟器开发-PPU笔记
  4. CSS实现水平居中的4种思路
  5. Elasticsearch + logstash中文指南
  6. [JAVA词形还原工具]Snowball
  7. Windows下 使用CodeBlocks配置OpenGL开发环境
  8. Swift 学习难点笔记
  9. HTTP代理协议 HTTP/1.1的CONNECT方法
  10. 【转】MyBatis学习总结(三)——优化MyBatis配置文件中的配置
  11. 用python给html里的css及js文件链接自动添加版本号
  12. 有N个数,组成的字符串,如012345,求出字串和取MOD3==0的子串,如012 12 123 45。
  13. 解决android 大图OOM的两种方法
  14. LOJ_2305_「NOI2017」游戏 _2-sat
  15. log4j.properties配置与将异常输出到Log日志文件实例
  16. bcftools合并vcf文件
  17. [转]新人常识普及:我们为什么必须会git和maven
  18. WinSock学习笔记
  19. 最全的select加锁分析(Mysql)
  20. git clone错误 fatal: early EOF fatal: index-pack failed

热门文章

  1. 虚拟机选择配置:解决tomcat内存溢出
  2. iOS:文本视图控件UITextView的详细使用
  3. delphi Align属性
  4. 推送代码分支时出现:fatal: &#39;origin&#39; does not appear to be a git repository
  5. Spark Streaming updateStateByKey和mapWithState源码解密
  6. :视频播放器与Handler 完美调用
  7. string和char*的区别以及const_cast&lt;&gt;()
  8. 2017.12.27 sqlSessionFactory和sqlSession(to be continued)
  9. PHP实现程序单例执行
  10. 树莓派学习笔记——GPIO功能学习