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. Mysql存储引擎之TokuDB以及它的数据结构Fractal tree(分形树)

    在目前的Mysql数据库中,使用最广泛的是innodb存储引擎.innodb确实是个很不错的存储引擎,就连高性能Mysql里都说了,如果不是有什么很特别的要求,innodb就是最好的选择.当然,这偏文 ...

  2. OkHttp:Java 平台上的新一代 HTTP 客户端

    OkHttp 简介 OkHttp 库的设计和实现的首要目标是高效.这也是选择 OkHttp 的重要理由之一.OkHttp 提供了对最新的 HTTP 协议版本 HTTP/2 和 SPDY 的支持,这使得 ...

  3. 使用jmeter进行性能测试-Jmeter教程及技巧汇总 (转)

    http://www.jmeter.cf/loadtesting-jmeter.html 为什么使用jmeter, 它免费开源, 不断发展, 功能逐渐强大. 可以做功能,负载, 性能测试.一套脚本可以 ...

  4. dede使用方法----如何转换时间戳

    dede用sql调用一个mysql时间,mysql的时间字段是时间戳展示的,突然不知道咋转换了,有点迷茫,结果找了下,发现其实很简单,直接用dede的就行了,如下: 完整时间:[field:datel ...

  5. 简单的cookie使用

    <html><head><script type="text/javascript">function getCookie(c_name){if ...

  6. HashMap Hashtable区别

    http://blog.csdn.net/java2000_net/archive/2008/06/05/2512510.aspx 我们先看2个类的定义 public class Hashtable ...

  7. css 去除 a,checkbox 框 出现虚线

    在开发过程中遇到checkbox框,第一次遇到还以为是系统自带的是这样 后来发现不是那样, 我们可以在使用css 去掉出现的虚线框,以下是我的解决方案代码: /* checkbox 去掉虚框*/:fo ...

  8. 【Codeforces 707B】Bakery 水题

    对每个storages找一下最短的相邻边 #include <cstdio> #define N 100005 #define inf 0x3f3f3f3f using namespace ...

  9. MySQL必知必会的查询

    前言: 据身边不少朋友反映,SQL长时间不用的话难免会生疏!本文的几个查询示例可以让你5分钟内快速回忆起MySQL中常用的基础查询语法! ------------ 如何用MySQL解决一些常见问题的例 ...

  10. DFS经典题,reachable or not in a 2D maze

    [[0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0], [0, 1, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0], ...