行程压缩 [英] Run Length Compressing

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

问题描述

我正在尝试通过使用运行长度压缩来压缩二进制数字,但是我无法成功编写代码.请帮助我...感谢您的赞赏!
我的代码:

I am trying to compress binary numbers via using Run Length Compressing but i can not be successful i am writing my code. PLEASE HELP ME... Thanks for all your appreciation!!!

MY CODE:

#include <stdio.h>
#include <stdlib.h>
#define max 100
#define middle 50
#define cMax 1000
int main()
{
    int entrance = 0;
    int i = 0;
    int k = 0;
    int j = 0;
    int diffrence = 0;
    int zeroCounter = 0;
    int oneCounter = 0;
    int *p[max] = { 0 };
    int *zeroOne[middle] = { 0 };
    int *one[middle] = { 0 };
    int *convertedNumber[cMax] = { 0 };
        do{
            printf("Please enter integer 1 for Compress, 2 for Decompress\n");
            scanf("%d",&entrance);
                if(entrance == 1){
                    printf("Please Enter The Binary You Want to Compress\n");
                    scanf("%s",p);
                    for(i=0;p[i]!=0;i++)
                    {
                        if(p[i] == 0)
                        {
                            if(oneCounter!=0)
                            {
                                for(k=k;k<(k + oneCounter-1);k++){
                                    convertedNumber[k] = 0;
                                }
                                oneCounter = 0;
                            }
                            zeroCounter++;
                        }
                        else if(p[i]==1 && i!= 0)
                        {
                            if(zeroCounter!=0)
                            {
                                    for(k=k;diffrence>2;k++)
                                    {
                                        convertedNumber[k] = zeroCounter % 2;
                                    }
                                    zeroCounter = 0;
                                }
                            oneCounter++;
                        }
                        else{
                                if(i!=0)
                                {
                                    printf("Please check your binary number\n");
                                    break;
                                }
                            }
                        }
                        for(j=0;convertedNumber != 0;j++){
                            printf("%d",convertedNumber[j]);
                            if (convertedNumber== 0)
                            break;
                            }

                        }
            }while(entrance != 1 && entrance != 2);
    printf("Hello world!\n");
    return 0;
}

推荐答案

首先,行程压缩"这个术语有点太宽泛了.您可以使用游程长度方法以多种类似方式压缩数据.你是说RLE吗?这里是实现:
[ ^ ],另请参见 http://en.wikipedia.org/wiki/Run-length [
First of all, "run length compression" is a bit too wide term. You can compress data using run-length approach in a number of similar ways. Do you mean RLE? The here is the implementation:
[^], see also http://en.wikipedia.org/wiki/Run-length[^].

As to your C code, I cannot see even the attempt of creation of encoding/decoding function. Instead, you''ve just written some main function. Why? Ever heard of functions and other means of abstraction? Don''t entangle I/O into algorithm, to start with.

—SA


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

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