poj-1782 Run Length Encoding
http://poj.org/problem?id=1782
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3907 | Accepted: 1282 |
Description
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
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的更多相关文章
- SDUT 2352 Run Length Encoding
点我看题目 题意 :将给定的字符串编码,编码的规则根据两条,1.如果字符串里有连续相等的字符,就变为两个字符,一个是这些连续相同的字符的个数,另一个是这个字符,但是如果数量超过了9个,那就输出9再输出 ...
- Two-Pointer 之 Run Length Coding (RLC)
游程编码(Run Length Coding, RLC)是串处理中常见的预处理方法.其写法是典型的双指针(Two-Pointer).下面总结其写法1.输入为一串整数可以不把整数存在数组里
- 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, ...
- POJ 1579-Function Run Fun(内存搜索)
Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16503 Accepted: 8514 ...
- 游程编码(Run Length Code)
一.什么是游程编码 游程编码是一种比较简单的压缩算法,其基本思想是将重复且连续出现多次的字符使用(连续出现次数,某个字符)来描述. 比如一个字符串: AAAAABBBBCCC 使用游程编码可以将其描述 ...
- POJ.1379.Run Away(模拟退火)
题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...
- poj 1379 Run Away 模拟退火 难度:1
Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6482 Accepted: 1993 Descript ...
- POJ 1379 Run Away
题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
随机推荐
- 覆盖(override)和重载(overload)
覆盖(override)重写和 重载(overload) 继承,重写--->多态 我懂了,你懂吗 ,不看看文章 java 子类重写父类的方法应注意的问题 Java多态性理解
- Cocos2d-x 学习资料收集
框架源代码: http://code.google.com/p/cocos2d-x/downloads/list 搭建环境 http://blog.csdn.net/ccf19881030/artic ...
- Struts2中EL表达式取值
http://blog.csdn.net/cuihaiyang/article/details/41950141 (写的不错,可以知道为什么struts2可以用El取属性值的问题.正常el从reque ...
- C#程序将对象保存为json文件的方法
首先,从NuGet上下载JSON .Net,安装到所需项目中. 对象obj保存到文件的步骤: 1. 创建文件 // 获取当前程序所在路径,并将要创建的文件命名为info.json string fp ...
- wamp使用方法【总】
Apache与php配置:我们把php-5.2.9-Win32.zip解压到C盘根目录下,把文件夹名字改成PHP,这样方便一下. 1. 找到PHP目录下的“php.ini-dist”或者“php.in ...
- CSS 列表
CSS列表属性作用如下: 设置不同的列表项标记为有序列表 设置不同的列表项标记为无序列表 设置列表项标记为图像 列表 在HTML中,有两种类型的列表: 无序列表 - 列表项标记用特殊图形(如小黑点.小 ...
- javascript 浏览器执行断点
在javascript代码里面有个语句可以让浏览器执行到这里的时候触发断点,这个命令就是 debugger 很好用
- 理解java Web项目中的路径问题
本文以项目部署在tomcat服务器为例,其他相信也是一样的. 先说明请求页面的写法,在web中,页面路径主要写的有以下几种 1.请求重定向 2.浏览器的请求被服务器请求到新页面(我称为“转发”) 3. ...
- Lucene分页-----SearcherAfter
/** * 分页,SearcherAfter * @param query * @param pageIndex * @param pageSize */ public void searchPage ...
- 倒置字符串s中各字符的位置
倒置字符串s中各字符的位置 其中reverse函数可以写成更紧凑的形式 void reverse(char s[]){ int c,i,j; ,j=strlen(s)-;i<j;i++,j--) ...