需要一个返回排列的函数

时间:2019-02-24 19:51:51

标签: c#

我正在使用c#将应用程序作为我自己的项目。它叫做时间表制作器。 我需要完成的最后一段代码需要完成以下任务

我们有一个大小为N的数组,其中N是课程总数(理论+实验)

它由用户提供的2个变量计算。

我们分别拥有理论数和实验室数

N =理论数+实验数

现在假设N = 5;

编写一个需要输入2个东西的函数。

1。)要置换的阵列。

2。)要置换的字符。假设(I)(眼睛):v。

它返回另一个排列的数组。

string[] PermuteOnce(string[] str, string PermuteTill)
    {
        string[] Permuted = new string[TheoryN];
        Permuted = str;
        // CODE HERE
        return Permuted;
    }

样本输入输出;

String [5] ToPermute = {A,A,A,A,A}

Permuted = PermuteOnce(ToPermute,“ I”);

置换的现在包含{A,A,A,A,B}

一次又一次调用它,并传递Permuted。

置换的现在包含{A,A,A,A,C}

置换的现在包含{A,A,A,A,D}

置换的现在包含{A,A,A,A,E}

置换的现在包含{A,A,A,A,F}

置换的现在包含{A,A,A,A,G}

置换的现在包含{A,A,A,A,H}

置换的现在包含{A,A,A,A,I}

现在…

置换的现在包含{A,A,A,B,A}

置换的现在包含{A,A,A,C,A}

像这样的“ I”是置换的极限。

更多解释...。

这是我到目前为止所做的...但是它并不完美...

  

str = PermuteOnce(str,“ I”);

 int Shifter = 4;
    int Count = 1;
    string ChangeTo(int C)
    {
        switch(C)
        {
            case 1:
                {
                    return "A";
                }
            case 2:
                {
                    return "B";
                }
            case 3:
                {
                    return "C";
                }
            case 4:
                {
                    return "D";
                }
            case 5:
                {
                    return "E";
                }
            case 6:
                {
                    return "F";
                }
            case 7:
                {
                    return "G";
                }
            case 8:
                {
                    return "H";
                }
            case 9:
                {
                    return "I";
                }
            default:
                return ".";
        }
    }


string[] PermuteOnce(string[] str, string PermuteTill)
    {
        string[] Permuted = new string[TheoryN];
        Permuted = str;
        char x = Convert.ToChar( Permuted[Shifter] );
        int Ascii = Convert.ToInt32(x);
        Ascii++;
        Permuted[Shifter] = Convert.ToString(Convert.ToChar(Ascii));
        if (Permuted[Shifter] == "J")
        {
            Permuted[Shifter] = ChangeTo(Count);
            if (Shifter > 0)
            Permuted[Shifter - 1] = ChangeTo(Count);
            Shifter--;
            if (Shifter == -1 && Count != 9)
            {
                Shifter = 4;
                Count++;
            }
        }
        return Permuted;
    }

现在,我怎么知道我的要求是否得到满足? 当排列之一是“ AGABB”时。它从“ AAAAA”开始,到“ IIIII”结束

这是我需要排列的函数..

private void HRain_Click(object sender, EventArgs e)
    {
        // Set All Sections To A In The Start.
        for (int i = 0; i < TheoryN; i++) { Sections[i].Text = Convert.ToString(Convert.ToChar(65)); } 
        // Clear Display Screen / Allocate Query And str for processing.
        Result_Screen_L.Clear();
        Query = new string[TotalCourses];
        string[] str = new string[TheoryN];

        // Loop Should Run Untill All Permutations Are Printed. e.g (From 'AAAAA' , 'IIIII' is attained.)
        while (!(Sections[0].Text == "I" && Sections[1].Text == "I" && Sections[2].Text == "I" && Sections[3].Text == "I" && Sections[4].Text == "I"))
        {
            for (int i = 0; i < TheoryN; i++) { str[i] = Sections[i].Text.ToString(); } // move sections to str.
            MatchWithLabs(); // magic logic in this.
            for (int i = 0; i < TotalCourses; i++) { Query[i] = CourseName[i].Text + " (" + Sections[i].Text + ")"; } // set query to calculate timetable.
            //Result = new string[MaxItems * MaxItems]; // to store result in. 7*7.
            //CalculateTimeTable(); // magic here too.
            //if (CheckForClash(Result)) DisplayResultScreen(); // if no clash then print on screen <3.
            str = PermuteOnce(str, "I"); // your magic function.
            //rev = new Revision("ABCDEFGHI", "AAAAA");
            for (int i = 0; i < TheoryN; i++) { Sections[i].Text = Convert.ToString(str[i]); } // move permuted str back to Sections.
        }
    }

0 个答案:

没有答案