首页 > 代码库 > 数组案例

数组案例

 

             //36选7生成彩票 不许产生重号

            /*

            Random b = new Random();

 

            int[] a = new int[7];

            for (int i = 0; i < 7; i++)

            {

 

                a[i] = b.Next(36) + 1;

 

                for (int m = 0; m < i; m++)

                {

                    if (a[m] == a[i])

                    {

                        Console.Clear();

                        i = -1;

                        break;

                    }

 

                }

                while (i != -1)

                {

                    Console.WriteLine(a[i]);

                    break;

                }

            }

            */

          

 

           

           

 

 

            //36选7

            /*

            int[] a = new int[7];

            Random ran = new Random();

 

            //生成7个数,比较是否重复并赋值给数组每个元素

            for (; a[6] == 0; )

            {

                int n = ran.Next(36) + 1;

                for (int j = 0; j < 7; j++)

                {

                    if (a[j] == n)

                    {

                        break;

                    }

                    if (a[j] == 0)

                    {

                        a[j] = n;

                        break;

                    }

                }

            }

 

          

            for (int i = 0; i < 7; i++)

            {

                Console.Write(a[i] + "\t");

            }

            */

 

        

 

            //36选7

            /*

            Random b = new Random();

 

            int[] a = new int[7];

            for (int i = 0; i < 7; i++)

            {

 

                a[i] = b.Next(36) + 1;

                int n = 0;

                for (int m = 0; m < i; m++)

                {

                   

                    if (a[m] == a[i])

                    {

                        n = 1;

                        i--;

                        break;

                    }

 

                }

                if (n != 1)

                {

                    Console.WriteLine(a[i]);

                }

            }

 

            */

 

 

 

 

//正规冒泡程序

            //趟数=总个数-1  次数=总个数-趟数(按小于等于算)

            //趟数=总个数     次数=总个数+1-趟数(按小于算)

            /*

            int[]a=new int [7]{2,3,34,46,5,6,7};

            for (int i = 1; i < 7;i++ )//外层循环趟数

            {

                for (int m = 1; m < 8 - i;m++ )//内层循环次数

                {

                    if(a[m-1]<a[m])   //此为降序排列  若升序只需要改<为>

                    {

                        int t = a[m - 1];

                        a[m - 1] = a[m];

                        a[m] = t;

                    }

                   

                }

              

            }

            for(int i=0;i<7;i++)

            {

            Console.Write(a[i] + "\t");

            }

            */

 

 

            //冒泡之多循环不计循环量

            /*

            int[] a = new int[7] { 2, 3, 34, 46, 5, 6, 7 };

            for (int i = 0; i < 7; i++)

            {

                for (int m = 1; m < 7; m++)

                {

                    if (a[m - 1] < a[m])

                    {

                        int t = a[m - 1];

                        a[m - 1] = a[m];

                        a[m] = t;

                    }

 

                }

 

            }

            for (int i = 0; i < 7; i++)

            {

                Console.Write(a[i] + "\t");

            }

            */

 

 

            //升降序排列之拿一个数和其他数比较后先显示最大值,依次找完

            /*

            int[] a = new int[7] { 2, 3, 34, 46, 5, 6, 7 };

            for (int i = 0; i < 7; i++)       

            {

                for (int m = i+1; m < 7; m++)   

                {

                    if (a[i] < a[m])

                    {

                        int t = a[i];

                        a[i] = a[m];

                        a[m] = t;

                    }

 

                }

 

            }

            for (int i = 0; i < 7; i++)

            {

                Console.Write(a[i] + "\t");

            }

 

            */

 

/* string [] s=new string[6]

            {"12300004054","75189558794941","14765795678","179657847977","794657991","1716591"};

            Random a = new Random();

            int n = a.Next(6);//随机生成一个号码

            Console.Write(s[n]);

            */

 

 

 

            /*

            string[] s = new string[6] { "12300004054", "75189558794941", "14765795678", "179657847977", "794657991", "1716591" };

            Random a = new Random();

            while (true)//一直随机生成号码,全部显示出来

            {

                int n = a.Next(6);

                Console.WriteLine(s[n]);

            }

            */

 

 

 

 

 

            /*

            string[] s = new string[6] { "12300004054", "75189558794941", "14765795678", "179657847977", "794657991", "1716591" };

            Random a = new Random();

            while (true)

            {

                Console.Clear();//一直随机生成号码时,以前的清空,只显示现在这一个

                int n = a.Next(6);

                Console.WriteLine(s[n]);

            }

            */

 

            /*

            string[] s = new string[6] { "12300004054", "75189558794941", "14765795678", "179657847977", "794657991", "1716591" };

            Random a = new Random();

            DateTime overtime = DateTime.Now.AddSeconds(5);//从现在计时,5秒后停止

            while (DateTime .Now<=overtime)

            {

                Console.Clear();

                int n = a.Next(6);

                Console.WriteLine(s[n]);

            }

            */

 

 

 

            /*

            string[] s = new string[6] { "12300004054", "75189558794941", "14765795678", "179657847977", "794657991", "1716591" };

            Random a = new Random();

            DateTime overtime = DateTime.Now.AddSeconds(5);

            while (DateTime.Now <= overtime)

            {

                Console.Clear();

                int n = a.Next(6);

 

                Console.WriteLine(s[n]);

            }

            Console.Clear();

            Console.WriteLine("12334456");//全部清空,只显示这个

            */

 

 

 

           // Console.ForegroundColor = ConsoleColor.Red;在要显示的前方加此可以定义显示的颜色

         

 

  double sum = 0;

          

            double[] a = new double[10];

            for (int i = 0; i < 10; i++)

            {

                Console.Write("请输入第" + (i + 1) + "位评委的分值:");

                a[i] = Convert.ToDouble(Console.ReadLine());

 

                sum = sum + a[i];

            }

                double s = a[0], s1 = a[1], m = a[0], m1 = a[1];

                for (int n = 1; n < 10; n++)

                {

                    if (s < a[n])

                    {

                        s1 = s;//s最大s1次大,有大的就赋值给s,把余下的给s1,即次大

                        s = a[n];//一个一个往下顶

                    }

 

                   else if(s1<=a[n])                

                    {                        

                      s1=a[n];

                    }

                    if (m > a[n])

                    {

                        m1 = m;

                        m = a[n];

                    }

                      else if (m1>=a[n])
                    {
                        m1 = a[n];
                    }

 

 

 

                }

           

            Console.WriteLine((sum-s-s1-m-m1)/6.0);

 

 

数组案例