对一个座位表(二维数组)进行点名50次,输出点名结果。(0-19号)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
internal class zuoye1
{
static void Main(string[] args)
{
int[,] a=new int[4, 5] { { 0,19,12,13,4},{ 5,16,7,18,9},{ 10,11,2,3,14},{ 15,6,17,8,1} };//学号 //
Random rnd = new Random();
int[] arr= new int[50];//储存点名50次的结果
int[,] count= new int[4,5];//次数数组
int time=0;//次数
for (int i = 0; i < 50; i++)//获取每个位置被点名的次数
{
arr[i]=rnd.Next(0,20);
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
for (int k = 0; k < 50; k++)
{
if (arr[k] == a[i, j])//每次结果数组的值如果等于学号,次数+1
{
time += 1;
}
}
count[i, j] = time;
time = 0;//一个位置统计完后,次数清零
Console.Write("{0}\t",count[i, j]);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}