ZOJ2478 Encoding 2017-04-18 23:02 43人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- ImageView一例 分类: H1_ANDROID 2013-10-30 23:02 1812人阅读 评论(0) 收藏
参考自<疯狂android讲义>2.4节 效果如下: 当点击图上某点时,将之附近放大至下图. 布局文件: <LinearLayout xmlns:android="http ...
- POJ3273 Monthly Expense 2017-05-11 18:02 30人阅读 评论(0) 收藏
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25959 Accepted: 10021 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- To zero
Let bygone be bygone. Now everything changed. In fact, everything occurs to me cause I am a loser i ...
- RNN LSTM 介绍
[RNN以及LSTM的介绍和公式梳理]http://blog.csdn.net/Dark_Scope/article/details/47056361 [知乎 对比 rnn lstm 简单代码] ...
- oracle内存结构
一.内存结构 SGA(System Global Area):由所有服务进程和后台进程共享: PGA(Program Global Area):由每个服务进程.后台进程专有:每个进程都有一个PGA. ...
- 大型运输行业实战_day10_1_自定义事务管理类
1.创建事务管理类 TransactionManager.java package com.day02.sation.transaction; import com.day02.sation.uti ...
- with as (转)
sql with as 用法(适用sqlserver,好像oracle也适用) Server 2005中提供了公用表表达式(CTE),使用CTE,可以使SQL语句的可维护性,同时,CTE要比表变量的效 ...
- 'org.springframework.beans.factory.xml.XmlBeanFactory' is deprecated
'org.springframework.beans.factory.xml.XmlBeanFactory' is deprecated XmlBeanFactory这个类已经被摒弃了.可以用以下代替 ...
- Infinity,NaN
常量 说明 Infinity 表示正无穷大的特殊值. -Infinity 表示负无穷大的特殊值. NaN Number 数据类型的一个特殊成员,用来表示“非数字”(NaN) 值. undefined ...
- How Many Answers Are Wrong(带权并查集)
How Many Answers Are Wrong http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS ( ...
- iOS 静态库的封装
参考网址:http://www.jianshu.com/p/b754709135fb http://www.jianshu.com/p/443a5b8f3894 注意:封装静态库时要注意的地方: ...
- 用SQL2000还原bak文件
1.右击SQL Server 2000实例下的“数据库”文件夹.就是master等数据库上一级的那个图标.选择“所有任务”,“还原数据库” 2.在“还原为数据库”中填上你希望恢 复的数据库名字.这个名 ...