Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多维数组检查器_C#_Arrays_Visual Studio_Multidimensional Array - Fatal编程技术网

C# 多维数组检查器

C# 多维数组检查器,c#,arrays,visual-studio,multidimensional-array,C#,Arrays,Visual Studio,Multidimensional Array,下面是一个c#程序,类似于我必须创建的东西,我已经多次尝试过,但都没有成功 如果在主方法中,“int[][]lottoNumbers”和该数组中的所有相对“new int[]”被初始化为int[,]lottoNumbers。PrintWinners、CheckNumber、CheckSups和PrintChecks方法中还需要进行哪些其他更改,以适应此已更改的声明二维数组 我曾多次尝试这样做,但我一直发现索引超出了数组错误的范围 //Number of supplementaries i

下面是一个c#程序,类似于我必须创建的东西,我已经多次尝试过,但都没有成功

如果在主方法中,“int[][]lottoNumbers”和该数组中的所有相对“new int[]”被初始化为int[,]lottoNumbers。PrintWinners、CheckNumber、CheckSups和PrintChecks方法中还需要进行哪些其他更改,以适应此已更改的声明二维数组

我曾多次尝试这样做,但我一直发现索引超出了数组错误的范围

    //Number of supplementaries in each draw
    const int SUPP = 2;

    /* Calls the methods to execute the program
     * 
     * precondition: none
     * postcondition: returns a series of strings and integers
     */
    static void Main() {
        const int NUMBER_OF_ROWS = 9;

        int[][] lottoNumbers ={ 
                         new int [] { 4, 7, 19, 23, 28, 36},
                         new int [] { 14, 18, 26, 34, 38, 45},
                         new int [] { 8, 10,11, 19, 28, 30},
                         new int [] {15, 17, 19, 24, 43, 44},
                         new int [] { 10, 27, 29, 30, 32, 41},
                         new int [] {9, 13, 26, 32, 37,  43},
                         new int [] {1, 3, 25, 27, 35, 41},
                         new int [] {7, 9, 17, 26, 28, 44},
                         new int [] {17, 18, 20, 28, 33, 38}
                          };

        int[] drawNumbers = new int[] { 44, 9, 17, 43, 26, 7, 28, 19 };


        TitleMessage();
        PrintYourNumbers(lottoNumbers);
        PrintDrawNumbers(drawNumbers);
        PrintChecks(lottoNumbers, drawNumbers, lottoNumbers.Length);

        ExitProgram();
    }//end Main


    /* Print welcome message
     * 
     * precondition: none
     * postcondition: returns the string
     */
    static void TitleMessage() {
        Console.WriteLine("\n\t Welcome to Lotto Checker \n\n\n");
    } //end TitleMessage


    /* Display the list of games created
     * 
     * precondition: list must be a two-dimentional array containing integers
     * postcondition: returns the list of games on separate lines (as strings)
     */
    static void PrintYourNumbers(int[][] list) {
        Console.WriteLine("Your Lotto numbers are:\n");
        for (int i = 0; i < list.Length; i++) {
            Console.Write("Game  {0,3}:", i + 1);
            for (int j = 0; j < list[i].Length; j++) {
                Console.Write("  {0,2}", list[i][j]);
            }
            Console.WriteLine("\n\n");
        }
    } //end PrintYourNumbers


    /* Display the single draw list created
    * 
    * precondition: list must be a two-dimentional array containing integers
    * postcondition: returns the draw list
    */
    static void PrintDrawNumbers(int[] list) {
        Console.WriteLine("\n\n Lotto Draw Numbers are: \n");
        for (int i = 0; i < list.Length; i++) {
            Console.Write("  {0,2}", list[i]);
        }
        Console.WriteLine("\n");
    } //end PrintDrawNumbers


    /* Display the string of winning numbers and sups
    * 
    * precondition: all parameters must be integers, yourNums must be 2D array,
    *                  drawNums must be single array, 
    *                  gameNum > 0 and < length of yourNums  
    * postcondition: returns the winning values on separate lines (as a string)
    */
    static void PrintWinners(int[][] yourNum, int[] drawNum, int gameNum) {
        int winningNum = 0, winningSup = 0;

        winningNum = CheckNumbers(yourNum, drawNum, gameNum);
        winningSup = CheckSups(yourNum, drawNum, gameNum);

        Console.WriteLine("\n\n\t found {0} winning numbers and {1} supplementary numbers in Game {2}\n\n", winningNum, winningSup, gameNum + 1);
    } //end CheckGame


    /* Compare game numbers against draw numbers
    * 
    * precondition: all parameters must be integers, yourNums must be 2D array,
    *                  drawNums must be single array, 
    *                  gameNum > 0 and < length of yourNums  
    * postcondition: returns the number of winning numbers
    */
    static int CheckNumbers(int[][] yourNum, int[] drawNum, int gameNum) {
        int winningNumber = 0;
        for (int i = 0; i < yourNum[gameNum].Length; i++) {
            for (int j = 0; j < drawNum.Length - SUPP; j++) {
                if (yourNum[gameNum][i] == drawNum[j]) {
                    winningNumber++;
                }
            }
        }
        return winningNumber;
    } //end CheckNumbers


    /* Compare game sup numbers against draw numbers
    * 
    * precondition: all parameters must be integers, yourNums must be 2D array,
    *                  drawNums must be single array, 
    *                  gameNum > 0 and < length of yourNums  
    * postcondition: returns the number of winning sups
    */
    static int CheckSups(int[][] yourNum, int[] drawNum, int gameNum) {
        int winningSup = 0;

        for (int j = 0; j < yourNum[gameNum].Length; j++) {
            for (int k = drawNum.Length - SUPP; k < drawNum.Length; k++) {
                if (yourNum[gameNum][j] == drawNum[k]) {
                    winningSup++;
                }
            }
        }
        return winningSup;
    } //end CheckSups

    /* Prints each game's winning numbers and sups
     * 
     * precondition: all parameters must be integers, yourNums must be 2D array,
     *                  drawNums must be single array, 
     *                  gameNum > 0 and < length of yourNums  
     * postcondition: prints each game's winning number & sup count
     */
    static void PrintChecks(int[][] yourNums, int[] drawNums, int gameNum) {
        for (int i = 0; i < gameNum; i++) {
            PrintWinners(yourNums, drawNums, i);
        }
    } //end PrintChecks


    /* Print exit message
     * 
     * precondition: none
     * postcondition: returns the string
     */
    static void ExitProgram() {
        Console.Write("\n\nPress any key to exit program: ");
        Console.ReadKey();
    }//end ExitProgram


} //end class Program
//每张图纸中的补充资料数量
常数int SUPP=2;
/*调用方法以执行程序
* 
*前提条件:无
*后置条件:返回一系列字符串和整数
*/
静态void Main(){
常量整数行数=9;
int[]lottoNumbers={
新int[]{4,7,19,23,28,36},
新int[]{14,18,26,34,38,45},
新int[]{8,10,11,19,28,30},
新int[]{15,17,19,24,43,44},
新int[]{10,27,29,30,32,41},
新的int[]{9,13,26,32,37,43},
新int[]{1,3,25,27,35,41},
新int[]{7,9,17,26,28,44},
新int[]{17,18,20,28,33,38}
};
int[]drawNumber=新的int[]{44,9,17,43,26,7,28,19};
标题信息();
打印您的号码(彩票号码);
打印图纸编号(图纸编号);
打印检查(LottonMembers、DrawNumber、LottonMembers.Length);
ExitProgram();
}//端干管
/*打印欢迎信息
* 
*前提条件:无
*postcondition:返回字符串
*/
静态无效标题消息(){
Console.WriteLine(“\n\t欢迎使用乐透检查器\n\n\n”);
}//结束标题消息
/*显示创建的游戏列表
* 
*前提条件:列表必须是包含整数的二维数组
*后置条件:以单独的行(字符串形式)返回游戏列表
*/
静态无效打印编号(int[][]列表){
Console.WriteLine(“您的乐透号码是:\n”);
for(int i=0;i0和0和0和0和const int SUPP = 2;

/* Calls the methods to execute the program
 * 
 * precondition: none
 * postcondition: returns a series of strings and integers
 */
static void Main() {
    const int NUMBER_OF_ROWS = 9;

    int[,] lottoNumbers ={
                     { 4, 7, 19, 23, 28, 36 },
                     { 14, 18, 26, 34, 38, 45 },
                     { 8, 10,11, 19, 28, 30 },
                     { 15, 17, 19, 24, 43, 44 },
                     { 10, 27, 29, 30, 32, 41 },
                     { 9, 13, 26, 32, 37, 43 },
                     { 1, 3, 25, 27, 35, 41 },
                     { 7, 9, 17, 26, 28, 44 },
                     {17, 18, 20, 28, 33, 38 }
                      };

    int[] drawNumbers = new int[] { 44, 9, 17, 43, 26, 7, 28, 19 };


    TitleMessage();
    PrintYourNumbers(lottoNumbers);
    PrintDrawNumbers(drawNumbers);
    PrintChecks(lottoNumbers, drawNumbers, lottoNumbers.GetLength(0));

    ExitProgram();
}//end Main


/* Print welcome message
 * 
 * precondition: none
 * postcondition: returns the string
 */
static void TitleMessage() {
    Console.WriteLine("\n\t Welcome to Lotto Checker \n\n\n");
} //end TitleMessage


/* Display the list of games created
 * 
 * precondition: list must be a two-dimentional array containing integers
 * postcondition: returns the list of games on separate lines (as strings)
 */
static void PrintYourNumbers(int[,] list) {
    Console.WriteLine("Your Lotto numbers are:\n");
    for (int i = 0; i < list.GetLength(0); i++) {
        Console.Write("Game  {0,3}:", i + 1);
        for (int j = 0; j < list.GetLength(1); j++) {
            Console.Write("  {0,2}", list[i, j]);
        }
        Console.WriteLine("\n\n");
    }
} //end PrintYourNumbers


/* Display the single draw list created
* 
* precondition: list must be a two-dimentional array containing integers
* postcondition: returns the draw list
*/
static void PrintDrawNumbers(int[] list) {
    Console.WriteLine("\n\n Lotto Draw Numbers are: \n");
    for (int i = 0; i < list.Length; i++) {
        Console.Write("  {0,2}", list[i]);
    }
    Console.WriteLine("\n");
} //end PrintDrawNumbers


/* Display the string of winning numbers and sups
* 
* precondition: all parameters must be integers, yourNums must be 2D array,
*                  drawNums must be single array, 
*                  gameNum > 0 and < length of yourNums  
* postcondition: returns the winning values on separate lines (as a string)
*/
static void PrintWinners(int[,] yourNum, int[] drawNum, int gameNum) {
    int winningNum = 0, winningSup = 0;

    winningNum = CheckNumbers(yourNum, drawNum, gameNum);
    winningSup = CheckSups(yourNum, drawNum, gameNum);

    Console.WriteLine("\n\n\t found {0} winning numbers and {1} supplementary numbers in Game {2}\n\n", winningNum, winningSup, gameNum + 1);
} //end CheckGame


/* Compare game numbers against draw numbers
* 
* precondition: all parameters must be integers, yourNums must be 2D array,
*                  drawNums must be single array, 
*                  gameNum > 0 and < length of yourNums  
* postcondition: returns the number of winning numbers
*/
static int CheckNumbers(int[,] yourNum, int[] drawNum, int gameNum) {
    int winningNumber = 0;
    for (int i = 0; i < yourNum.GetLength(1); i++) {
        for (int j = 0; j < drawNum.Length - SUPP; j++) {
            if (yourNum[gameNum, i] == drawNum[j]) {
                winningNumber++;
            }
        }
    }
    return winningNumber;
} //end CheckNumbers


/* Compare game sup numbers against draw numbers
* 
* precondition: all parameters must be integers, yourNums must be 2D array,
*                  drawNums must be single array, 
*                  gameNum > 0 and < length of yourNums  
* postcondition: returns the number of winning sups
*/
static int CheckSups(int[,] yourNum, int[] drawNum, int gameNum) {
    int winningSup = 0;

    for (int j = 0; j < yourNum.GetLength(1); j++) {
        for (int k = drawNum.Length - SUPP; k < drawNum.Length; k++) {
            if (yourNum[gameNum, j] == drawNum[k]) {
                winningSup++;
            }
        }
    }
    return winningSup;
} //end CheckSups

/* Prints each game's winning numbers and sups
 * 
 * precondition: all parameters must be integers, yourNums must be 2D array,
 *                  drawNums must be single array, 
 *                  gameNum > 0 and < length of yourNums  
 * postcondition: prints each game's winning number & sup count
 */
static void PrintChecks(int[,] yourNums, int[] drawNums, int gameNum) {
    for (int i = 0; i < gameNum; i++) {
        PrintWinners(yourNums, drawNums, i);
    }
} //end PrintChecks


/* Print exit message
 * 
 * precondition: none
 * postcondition: returns the string
 */
static void ExitProgram() {
    Console.Write("\n\nPress any key to exit program: ");
    Console.ReadKey();
}//end ExitProgram