Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 
 
AC Code --Java
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- != 0) {
String a = sc.next();
char[] arr = a.toCharArray(); char[] zc = new char[10000];
int[] zs = new int[5000];
int j = 0;
zc[0] = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] == arr[i - 1]) {
zs[j]++;
} else {
zc[++j] = arr[i];
}
} for (int i = 0; i < j + 1; i++) {
if (zs[i] == 0)
System.out.print(zc[i]);
else
System.out.print(zs[i] + 1 + "" + zc[i]);
}
System.out.println();
}
}
}

 C 代码版

#include <stdio.h>

void out(char arr[100]);
int main(void)
{ int n=0,i=0;
char arr1[100][100];
while(scanf("%d",&n)!=EOF)
{
getchar();
for(i=0;i<n;i++)
{
gets(arr1[i]);
} for(i=0;i<n;i++)
{
out(arr1[i]);
}
} return 0;
}
void out(char arr[100])
{
char s[100];
int sum[100];
int i=0,j=0;
s[0]=arr[0];
sum[0]=1;
for(i=1;i<strlen(arr)+1;i++)
{
if(arr[i]==arr[i-1])
sum[j]++;
else
{
s[++j]=arr[i];
sum[j]=1;
}
}
s[j]='\0';
for(i=0;i<strlen(s);i++)
if(sum[i]!=1)
printf("%d%c",sum[i],s[i]);
else
printf("%c",s[i]);
printf("\n");
}

  

hdu 1020 Encoding的更多相关文章

  1. HDU 1020 Encoding POJ 3438 Look and Say

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. HDU 1020 Encoding 模拟

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. HDU 1020 Encoding【连续的计数器重置】

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. HDU 1020:Encoding

    pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  5. HDU 1020.Encoding-字符压缩

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  6. HDOJ 1020 Encoding

    Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...

  7. hdu 1020

    //自信满满地交上去~~but...超时了 #include <iostream> #include <string.h> #include <stdio.h> u ...

  8. HDU 1020(连续同字符统计 **)

    题意是要统计在一段字符串中连续相同的字符,不用再排序,相等但不连续的字符要分开输出,不用合在一起,之前用了桶排序的方法一直 wa,想复杂了. 代码如下: #include <bits/stdc+ ...

  9. HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

    并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could ...

随机推荐

  1. ClipDrawable 实现图片渐变现实

    clip.xml <?xml version="1.0" encoding="utf-8"?><clip xmlns:android=&quo ...

  2. 【BZOJ 1857】【SCOI 2010】传送带

    三分套三分,虽然简单,但是也得掌握,,, 时间复杂度$O(log_{1.5}^2 n)$ 一开始WA好几次发现是快速读入里没有return,这样也能过样例?_(:3J∠)_ #include<c ...

  3. 【BZOJ 1503】【NOI 2004】郁闷的出纳员

    $Splay$模板题. 复习一下伸展树的模板. 一定不要忘了push啊!!! 对于减工资后删掉员工的操作,我选择插入一个$min+delta_{减少的工资}$的节点,把它$Splay$到根,砍掉它自己 ...

  4. JAVA1种C++3种继承方式

    JAVA中只有一种public继承

  5. 通过JS实现网站繁体简体互换

    html部分 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  6. css-css权威指南学习笔记1

    第一章 CSS和文档 1.结构化HTML:(个人理解) 1.内容.样式.行为分离 2.标签语义化,什么样的标签做什么样的事 3.符合web标准 4.结构清晰,header.content.footer ...

  7. 【BZOJ-1367】sequence 可并堆+中位数

    1367: [Baltic2004]sequence Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 932  Solved: 348[Submit][S ...

  8. org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。

    二月 25, 2016 9:24:24 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin 警告: [SetPropertiesRul ...

  9. Oracle AWR 数据导入/导出的步骤

    LINUX状态下,连接oracle用户:su - oracle  1.上传采集快照.dmp文件至服务器  (dbid:4292035712)  919219826 2.在服务器端创建目录 (即文件夹a ...

  10. iOS设置圆角矩形和阴影效果

    1.设置圆角矩形 //设置dropview属性 _dropView.backgroundColor=[[UIColor whiteColor] colorWithAlphaComponent:0.8] ...