java游程编码 [英] java Run-length encoding

查看:253
本文介绍了java游程编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何开始我的作业。

I have no idea how to start my assignment.

我们必须制作一个游程编码程序,

We got to make a Run-length encoding program,

例如,用户输入此字符串:

for example, the users enters this string:

aaaaPPPrrrrr

aaaaPPPrrrrr

替换为

4a3P5r

有人可以帮助我开始使用它吗?

Can someone help me get started with it?

推荐答案

希望这能让你开始完成任务:

Hopefully this will get you started on your assignment:

行程编码背后的基本思想是连续发生的令牌像aaaa可以用更短的形式4a代替(意思是以下四个字符是'a')。这种类型的编码在计算机图形学的早期使用,以在存储图像时节省空间。那时候,视频卡支持少量颜色和图像通常具有相同的颜色,对于图像的重要部分连续都是相同的颜色)

The fundamental idea behind run-length encoding is that consecutively occurring tokens like aaaa can be replaced by a shorter form 4a (meaning "the following four characters are an 'a'"). This type of encoding was used in the early days of computer graphics to save space when storing an image. Back then, video cards supported a small number of colors and images commonly had the same color all in a row for significant portions of the image)

你可以读它维基百科上的详细信息

You can read up on it in detail on Wikipedia

http:// en.wikipedia.org/wiki/Run-length_encoding

为了对字符串进行行程编码,可以遍历输入字符串中的字符。有一个计数器,计算你连续看到相同字符的次数。当您看到另一个字符时,输出计数器的值,然后输出您一直在计算的字符。如果计数器的值为1(意味着您只看到一行中的一个字符),则跳过输出计数器。

In order to run-length encode a string, you can loop through the characters in the input string. Have a counter that counts how many times you have seen the same character in a row. When you then see a different character, output the value of the counter and then the character you have been counting. If the value of the counter is 1 (meaning you only saw one of those characters in a row) skip outputting the counter.

这篇关于java游程编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆