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 ...
随机推荐
- 如何在Ubuntu上配置scala教程
Scala是一门多范式的编程语言,一种类似java的编程语言,设计初衷是实现可伸缩的语言 .并集成面向对象和函数式变成的各种特性.这里为了学习spark特地配置了scala. 1.下载scala安装包 ...
- mysql 表被锁处理方案
1. 查询锁表信息 当前运行的所有事务 select * from information_schema.innodb_trx 当前出现的锁 select * from information_sch ...
- Java设计模式(二) 观察者模式
观察者模式: 定义了对象之间的一对多依赖,这样一来,当一个对象改变状态时,他的所有依赖者都会受到通知并自动更新. 1,定义事件源接口 package com.pattern.observer; pub ...
- AndroidPn
客户端的主要包说明 org.androidpn.client包下的文件 public class Constants { //包含静态数据 public class InvalidFormatExc ...
- 资源: StaticResource, ThemeResource
StaticResource ThemeResource 示例1.演示“StaticResource”相关知识点Resource/StaticResourceDemo.xaml <Page x: ...
- KVC、KVO、NSNotification、delegate 总结及区别
1.KVC,即是指 NSKeyValueCoding,一个非正式的Protocol,提供一种机制来间接访问对象的属性.而不是通过调用Setter.Getter方法访问.KVO 就是基于 KVC 实现的 ...
- 【转】ViewPager学习笔记(一)——懒加载
在项目中ViewPager和Fragment接口框架已经是处处可见,但是在使用中,我们肯定不希望用户在当前页面时就在前后页面的数据,加入数据量很大,而用户又不愿意左右滑动浏览,那么这时候ViewPag ...
- 【C++实现python字符串函数库】一:分割函数:split、rsplit
[C++实现python字符串函数库]split()与rsplit()方法 前言 本系列文章将介绍python提供的字符串函数,并尝试使用C++来实现这些函数.这些C++函数在这里做单独的分析,最后我 ...
- AS技巧合集「编码技巧篇」
转载:http://www.apkbus.com/forum.php?mod=viewthread&tid=254725&extra=page%3D2%26filter%3Dautho ...
- 【bzoj3611】 大工程
http://www.lydsy.com/JudgeOnline/problem.php?id=3611 (题目链接) 搞了1天= =,感觉人都变蠢了... 题意 给出一个n个节点的树,每条边边权为1 ...