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. Developing iOS8 Apps with Swift——iOS8概览

    iOS 8 概览 斯坦福公开课--Developing iOS8 Apps with Swift学习笔记 想学习Swift,但是相应的教程不是很多,在CoCoaChina社区闲逛时恰好发现了这门课程, ...

  2. gulp + browserSync 一起提高前端开发效率吧!

    前端开发的时候,每次修改代码后,要移动鼠标到浏览器选中再刷新查看效果,不知觉间我们的加班的时间又增加了0.5s, 真是罪孽!所以在使用gulp之后,就一直对能自动监听文件刷新页面的browserSyn ...

  3. 关于java中for和foreach循环

    for循环中的循环条件中的变量只求一次值!具体看最后的图片 foreach语句是java5新增,在遍历数组.集合的时候,foreach拥有不错的性能. foreach是for语句的简化,但是forea ...

  4. 169. Majority Element(C++)

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  5. maven项目显示红叉的解决方法

    我们在做maven项目时,有时项目会显示红叉,但是项目本身并没有错误,如何去掉呢? 下面是我的解决方法 1.点击项目再右键,在搜索框中输入facets 2.把Dynamic Web Module的版本 ...

  6. ES 中文分词

    一.大名鼎鼎的中文插件IK的安装配置 1. 在插件目录中建立IK的目录 mkdir $ES_HOME/plugins/analysis-ik 2. 下载IK 的类库jar 文件到IK目录 cd $ES ...

  7. Centos安装编译环境

    众所周知,在安装完Centos完了以后,是没有编译环境的,我自己挂上光盘,手动安装解决了几十的依赖关系,在配置些软件时,还是经常报些依赖软件包的缺失,很是头疼,后来百度了下centos需要装的编译环境 ...

  8. MyISAM 和 InnoDB 讲解[转]

    MyISAM 和 InnoDB 讲解 InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级处 ...

  9. 十进制和n进制的转换(10进制转换为36进制)

    答案如下: void Convert() { map<int ,string> maps; maps[0]="0"; maps[1]="1"; ma ...

  10. 关于 Log4Net

    Log4Net是用来记录日志的,可以将程序运行过程中的信息输出到一些地方(文件.数据库.EventLog等),日志就是程序的黑匣子,可以通过日志查看系统的运行过程,从而发现系统的问题.日志的作用:将运 ...