博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1782 Run Length Encoding
阅读量:5050 次
发布时间:2019-06-12

本文共 2019 字,大约阅读时间需要 6 分钟。

Run Length Encoding
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 5006   Accepted: 1560

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

AAAAAABCCCC12344

Sample Output

6A1B14C11123124 题意:找出连续相同的字符有多少个    (1)2<=连续字符长度<=9 输出个数+字符;>9把9个先输出,后面的截断再判断    (2)没有相同字符的子序,在第一个和最后一个字符前面输出1,如果字符是1,就用1转意,所以1个1就是11;

AC代码:

#include
#include
using namespace std;const int N=1010;char s[N];int main(){ #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE while(gets(s)!=NULL){ int len=strlen(s); int i=0,j; while(i
=9) break; } if(k>1) { printf("%d%c",k,s[i-1]); i++; } if(i>=len) break; if(s[i]!=s[i+1]){ printf("1"); while(s[i]!=s[i+1]&&i

 

转载于:https://www.cnblogs.com/kun-/p/9746996.html

你可能感兴趣的文章
20165235 第八周课下补做
查看>>
[leetcode] 1. Two Sum
查看>>
iOS 日常工作之常用宏定义大全
查看>>
PHP的SQL注入技术实现以及预防措施
查看>>
MVC Razor
查看>>
软件目录结构规范
查看>>
Windbg调试Sql Server 进程
查看>>
linux调度器系列
查看>>
mysqladmin
查看>>
解决 No Entity Framework provider found for the ADO.NET provider
查看>>
SVN服务器搭建和使用(三)(转载)
查看>>
Android 自定义View (三) 圆环交替 等待效果
查看>>
设置虚拟机虚拟机中fedora上网配置-bridge连接方式(图解)
查看>>
HEVC播放器出炉,迅雷看看支持H.265
查看>>
[置顶] Android仿人人客户端(v5.7.1)——人人授权访问界面
查看>>
Eclipse 调试的时候Tomcat报错启动不了
查看>>
【安卓5】高级控件——拖动条SeekBar
查看>>
ES6内置方法find 和 filter的区别在哪
查看>>
Android入门之文件系统操作(二)文件操作相关指令
查看>>
Android实现 ScrollView + ListView无滚动条滚动
查看>>