标题:[比较难的一道题]乱序算法-打乱文件内容
取消只看楼主
ym333mmm
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-9-12
 问题点数:0 回复次数:2 
[比较难的一道题]乱序算法-打乱文件内容
穷举4个字节存入文件中但是写入时是顺序的我想打乱里面的内容但是没想好什么算法,截图如下:



源代码原文如下:
using System;
using
using System.Text;
class Program
{
    static void Main()
    {
        //------------------准备工作---------------------------------//
        //创建文件
        FileStream fs;

        string filename = "123.txt";
        try
        {
            fs = File.Create(filename);
        }
        catch (IOException ex)
        {
            Console.WriteLine(ex.Message);
            return;
        }
            //------------------准备工作---------------------------------//
            //创建穷举字符数组

            byte[] income = new byte[5];
            income[0] = 0x00;
            income[1] = 0x00;
            income[2] = 0x00;
            income[3] = 0x00;
            //第一圈把全部是0的情况写进去
            fs.Write(income, 0, income.Length);
            do
            {
               
                    income[3]++;
                    if (income[3] == 0)
                    {
                        income[2]++;
                        if (income[2] == 0)
                        {
                            income[1]++;
                            if (income[1] == 0)
                            {
                                income[0]++;
                            }
                        }
                    }
                  

                fs.Write(income, 0, income.Length);
               
                //Console.WriteLine("写入成功!!");

                if (income[0] == 0xFF)
                {
                    if (income[1] == 0xFF)
                    {
                        if (income[2] == 0xFF)
                        {
                            Console.WriteLine(income.ToString());
                            if (income[3] == 0xFF)
                            {
                                break;
                            }
                        }
                    }
                }
            } while (true);
            fs.Flush();
        fs.Close();
     
        }
}

要求1:以4个字节为单位读取,将文件里的顺序打乱重写进文件
要求2:内容不重复,而且实雪崩效应良好.
问题1:如果将数据写入数据库会不会有压缩效果(当前占用硬盘16GB),把它降下来.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
事先声明本人白菜O(∩_∩)O~
搜索更多相关主题的帖子: 工作 源代码 class using 
2011-09-12 22:01
ym333mmm
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-9-12
得分:0 
问题比较难 我想了很久没有优良的办法
2011-09-12 22:01
ym333mmm
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-9-12
得分:0 
沉了顶下~~~
2011-09-19 19:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-349788-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.537979 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved