http://poj.org/problem?id=1782

Run Length Encoding
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 3907   Accepted: 1282

Description

Your task is to write a program that performs a simple form of run-length encoding, as described by the rules below. 
Any sequence of between 2 to 9 identical characters is encoded by two characters. The first character is the length of the sequence, represented by one of the characters 2 through 9. The second character is the value of the repeated character. A sequence of more than 9 identical characters is dealt with by first encoding 9 characters, then the remaining ones. 
Any sequence of characters that does not contain consecutive repetitions of any characters is represented by a 1 character followed by the sequence of characters, terminated with another 1. If a 1 appears as part of the sequence, it is escaped with a 1, thus two 1 characters are output. 

Input

The input consists of letters (both upper- and lower-case), digits, spaces, and punctuation. Every line is terminated with a newline character and no other characters appear in the input.

Output

Each line in the input is encoded separately as described above. The newline at the end of each line is not encoded, but is passed directly to the output.

Sample Input

AAAAAABCCCC
12344

Sample Output

6A1B14C
11123124
#include<stdio.h>
#include<string.h>
int main()
{
char str[200];
int i,j,cnt,l;
while(gets(str))
{
if (!str[0])
{
putchar(10);
continue;
}
cnt=1;
for(i=0;str[i];i++)
{
if (str[i] == str[i+1])
{
for ( j = i ; str[i] == str[i+1] && (i-j) < 8 ; i++ );
printf("%d%c", i-j+1, str[i]);
}
else
{
printf("1");
for(j=i;str[j];j++)
{
if(str[j]!=str[j+1])
{
if(str[j]=='1')
printf("1");
printf("%c",str[j]);
}
else
break;
}
printf("1");
i=j-1;
}
} printf("\n");
memset(str, 0, sizeof(str));
}
return 0;
}

poj-1782 Run Length Encoding的更多相关文章

  1. SDUT 2352 Run Length Encoding

    点我看题目 题意 :将给定的字符串编码,编码的规则根据两条,1.如果字符串里有连续相等的字符,就变为两个字符,一个是这些连续相同的字符的个数,另一个是这个字符,但是如果数量超过了9个,那就输出9再输出 ...

  2. Two-Pointer 之 Run Length Coding (RLC)

    游程编码(Run Length Coding, RLC)是串处理中常见的预处理方法.其写法是典型的双指针(Two-Pointer).下面总结其写法1.输入为一串整数可以不把整数存在数组里

  3. Count and Say (Array Length Encoding) -- LeetCode

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  4. POJ 1579-Function Run Fun(内存搜索)

    Function Run Fun Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16503   Accepted: 8514 ...

  5. 游程编码(Run Length Code)

    一.什么是游程编码 游程编码是一种比较简单的压缩算法,其基本思想是将重复且连续出现多次的字符使用(连续出现次数,某个字符)来描述. 比如一个字符串: AAAAABBBBCCC 使用游程编码可以将其描述 ...

  6. POJ.1379.Run Away(模拟退火)

    题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...

  7. poj 1379 Run Away 模拟退火 难度:1

    Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6482   Accepted: 1993 Descript ...

  8. POJ 1379 Run Away

    题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...

  9. POJ 1379 Run Away 【基础模拟退火】

    题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...

随机推荐

  1. sharepoint中的YesNo字段

    sharepoint中的YesNo字段实际上是一个Boolean字段,性格有点特别,如果IsShow是一个YesNo字段,使用caml查询的时候值为”1“(Yes)”0“(No),Item[IsSho ...

  2. IIS本地部署项目出错

    今天,打开部署在本地IIS的项目发现出错了.报的错,跟没有连接网络一样的.我当时有点懵,过一会儿再静下心来,想想这是什么原因. 第一步,把所有部署的项目,都打开看了一下,方便找出对比. 发现,绑定了I ...

  3. 为什么每个浏览器都有Mozilla

    你是否好奇标识浏览器身份的User-Agent,为什么每个浏览器都有Mozilla字样? Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ...

  4. iOS SDwebImage 使用说明

    SDWebImage托管在github上.https://github.com/rs/SDWebImage 这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下 ...

  5. iOS军火库-好用的ActionSheetView

    GitHub地址 一个自定义的ActionSheetView,支持显示标题,默认选中,使用block回调. 使用说明 [GLActionSheet showWithDataSource:@[@&quo ...

  6. CSS 背景

    CSS 背景属性用于定义HTML元素的背景. CSS 属性定义背影效果: background-color background-image background-repeat background- ...

  7. _BLOCK_TYPE_IS_VALID 问题解析及处理

    直接原因: 释放内存时,内存已经被修改或释放. 产生可能: 1.内存越界操作,踩了待释放指针头信息. 2.重复释放指针. 处理: 采用排除法,逐步屏蔽掉一些代码,当屏蔽某些代码时,不抛此异常,说明问题 ...

  8. 【原创】win7同局域网下共享文件

    本文章用于解决win7局域网共享文件问题: 首先保证两台机器可以ping通: 检测方法: win+R输入cmd打开命令行,输入ping  对方主机ip 不知对方ip可以在在命令行中输入ipconfig ...

  9. js中的forin

    前言 自己在平时没事干练练手,发现的以前一直以为是错的.幸亏今天知道了,要不说起来自己还不知道呢. 过程 遍历前置页面上的textbox,给他们赋值(js). 一开始自己用forin遍历的. 如论如何 ...

  10. php接口开发--复制缩减Codeigniter的车轮

    接口需求: 输出json 单一入口 安全 http://segmentfault.com/q/1010000000143852基于token验证?session? 缓存 session cookie ...