Encoding


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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

Output

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

Sample Input

2

ABC

ABBCCC

Sample Output

ABC

A2B3C


Author: ZHANG, Zheng

Source: Zhejiang Provincial Programming Contest 2005

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <functional>
#include <bitset>
#include <string> using namespace std; #define LL long long
#define INF 0x3f3f3f3f int a[30];
char ch[105]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",ch);
int len=strlen(ch);
memset(a,0,sizeof a);
int sum=1;
char s=ch[0];
for(int i=1;i<len;i++)
{
if(ch[i]==s) sum++;
else
{
if(sum==1) printf("%c",s);
else printf("%d%c",sum,s);
sum=1;s=ch[i];
}
}
if(sum==1) printf("%c",s);
else printf("%d%c",sum,s);
printf("\n");
}
return 0;
}

ZOJ2478 Encoding 2017-04-18 23:02 43人阅读 评论(0) 收藏的更多相关文章

  1. Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

  2. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  3. POJ3281 Dining 2017-02-11 23:02 44人阅读 评论(0) 收藏

    Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...

  4. ImageView一例 分类: H1_ANDROID 2013-10-30 23:02 1812人阅读 评论(0) 收藏

    参考自<疯狂android讲义>2.4节 效果如下: 当点击图上某点时,将之附近放大至下图. 布局文件: <LinearLayout xmlns:android="http ...

  5. POJ3273 Monthly Expense 2017-05-11 18:02 30人阅读 评论(0) 收藏

    Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25959   Accepted: 10021 ...

  6. Hdu2204 Eddy's爱好 2017-06-27 16:11 43人阅读 评论(0) 收藏

    Eddy's爱好 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  7. Hadoop常见异常及其解决方案 分类: A1_HADOOP 2014-07-09 15:02 4187人阅读 评论(0) 收藏

    1.Shell$ExitCodeException 现象:运行hadoop job时出现如下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : at ...

  8. NYOJ-235 zb的生日 AC 分类: NYOJ 2013-12-30 23:10 183人阅读 评论(0) 收藏

    DFS算法: #include<stdio.h> #include<math.h> void find(int k,int w); int num[23]={0}; int m ...

  9. HDU2033 人见人爱A+B 分类: ACM 2015-06-21 23:05 13人阅读 评论(0) 收藏

    人见人爱A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

随机推荐

  1. Boost.Hana

    Boost.Hana Boost.Hana 是一个元编程的库.它为不同种类数据的集合以及类型的集合提供了容器和算法. #include <boost/hana.hpp> namespace ...

  2. Python环境配置, atom-python配置

    环境变量 路径 在window下配置环境变量,配置到文件夹级就可以了: D:\program\python3 编码 因为windows默认的编码是ASIIC,所以使用atom时候中文是乱码,需要在环境 ...

  3. Python修改文件的两种方法

    目录: 一.以占用内存的方式修改文件 二.以占用硬盘的方式修改文件 引言 文件修改的方法从操作方式上大致可以分为两类,一种是以占用电脑内存的方式,将文件读取到内存中修改再存回硬盘:第二种方法是分别打开 ...

  4. ispostback的使用

    如果form表单属性里没有 runat="server"就不能使用ispostback因为不会生成__viewstate隐藏域

  5. css position定位详解

    position:static 默认方式: position:relative 相对定位,相对于原有位置进行移动,并且保留它在文件流中的占位: position:absolute 绝对定位,相对于最近 ...

  6. 第八章 高级搜索树 (b5)B-树: 删除

  7. centos 系统下彻底删除mysql

    yum remove mysql mysql-server mysql-libs compat-mysql51 rm -rf /var/lib/mysql (删除数据库) rm /etc/my.cnf ...

  8. 关于元表,self,元方法__index

    这是需要仔细分辨的几个概念. 元表:相当于table的隐藏属性. 只有固定的一些方法,如__index,__tostring,__add等,称为元方法. 虽然是固定的,但是任何table都可以作为任何 ...

  9. JFinal架构简介

    JFinal 是基于Java 语言的极速 web 开发框架,其核心设计目标是开发迅速.代码量少.学习简单.功能强大.轻量级.易扩展.Restful.在拥有Java语言所有优势的同时再拥有ruby.py ...

  10. Halcon小函数的封装和代码导出

    一.Halcon小函数的封装和修改 1.名词解释: 算子:指Halcon中最基础.最底层的函数(即你看不到它的代码实现),一个算子只有一句话,例如threshold算子. 小函数:由多个算子组合成的函 ...