hdu 1020 Encoding
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
Output
Sample Input
Sample Output
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的更多相关文章
- 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 ...
- HDU 1020 Encoding 模拟
Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU 1020 Encoding【连续的计数器重置】
Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU 1020:Encoding
pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDU 1020.Encoding-字符压缩
Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDOJ 1020 Encoding
Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...
- hdu 1020
//自信满满地交上去~~but...超时了 #include <iostream> #include <string.h> #include <stdio.h> u ...
- HDU 1020(连续同字符统计 **)
题意是要统计在一段字符串中连续相同的字符,不用再排序,相等但不连续的字符要分开输出,不用合在一起,之前用了桶排序的方法一直 wa,想复杂了. 代码如下: #include <bits/stdc+ ...
- HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)
并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could ...
随机推荐
- supervisor program配置实例
program 配置 上面我们已经把 supervisrod 运行起来了,现在可以添加我们要管理的进程的配置文件.可以把所有配置项都写到 supervisord.conf 文件里,但并不推荐这样做,而 ...
- [转]Spring注解原理的详细剖析与实现
原文地址:http://freewxy.iteye.com/blog/1149128/ 本文主要分为三部分: 一.注解的基本概念和原理及其简单实用 二.Spring中如何使用注解 三.编码剖析spri ...
- [转]理解RESTful架构
原文地址:http://www.ruanyifeng.com/blog/2011/09/restful 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件" ...
- 【转】css布局居中和CSS内容居中区别和对应DIV CSS代码
原文地址:http://www.divcss5.com/jiqiao/j771.shtml css布局居中和CSS内容居中区别和对应DIV CSS代码教程与图文代码案例篇 对于新手来说DIV CSS布 ...
- 【BZOJ 1031】【JSOI 2007】字符加密Cipher
后缀数组模板题,看了一天的后缀数组啊,我怎么这么弱TwT #include<cstdio> #include<cstring> #include<algorithm> ...
- highstock-处理时间需要处理世界时间偏移量
highstock的数据格式采用的是[[时间,数据],[时间,数据],[时间,数据],[时间,数据]],而时间采用的是13位的毫秒值,如[1133136000000,69.66],采用的时间格式为UT ...
- Timer和DPC
一般两种方法使用/设置定时器,一种是使用I/O定时器例程,一种是使用DPC例程.1.定时器的实现1)使用I/O定时器例程NTSTATUSIoInitializeTimer(IN PDEVICE_OBJ ...
- Search and Replace搜寻与替换工具
一个功能强大的搜寻与替代工具.它可以在同一部硬盘中对所有的文件进行搜寻与替换的功能,也可以对Zip文件中的文件做搜寻,支持特殊字符条件表达式搜寻,或是以脚本文件(Script)做搜寻替换工作,也可以以 ...
- Qt出现cannot find -IGL错误
Solution: sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev
- HDU1150 Machine Schedule
匈牙利算法 目前为止还是半懂不懂的状态 #include<iostream> #include<cstdio> #include<cstring> using na ...