码迷,mamicode.com
首页 > 编程语言 > 详细

C#_数组

时间:2015-07-09 00:25:26      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

//输入n个学生分数,排名
            Console.WriteLine("请输入学生的人数:");
            int n = Convert.ToInt32(Console.ReadLine());

            int[] fs = new int[n];

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("第{0}个学生的分数:", i + 1);
                fs[i] = Convert.ToInt32(Console.ReadLine());
            }

            for (int j = 0; j < fs.Length - 1; j++)
            {
                for (int k = 0; k < fs.Length - 1 - j; k++)
                {
                    if (fs[k] < fs[k + 1])
                    {
                        int cc = fs[k + 1];
                        fs[k + 1] = fs[k];
                        fs[k] = cc;
                    }
                }
            }
            Console.WriteLine("*********************");
            //输出
            for (int x = 0; x < fs.Length; x++)
            {
                Console.WriteLine(fs[x]);
            }
//电视里  手机号码抽奖
            Console.WriteLine("请输入手机号个数:");
            int n = Convert.ToInt32(Console.ReadLine());

            string[] sj = new string[n];
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("请输入第{0}个手机号:", i + 1);
                sj[i] = Console.ReadLine();
            }
            //随机生成       
            DateTime d = DateTime.Now;
            DateTime dt = d.AddSeconds(10);

            while (true)
            {
                Console.Clear();

                Random aa = new Random();
                int a = aa.Next(n);

                Console.WriteLine(sj[a]);



                if (dt.ToString("yyyyMMddHHmmss") == DateTime.Now.ToString("yyyyMMddHHmmss"))
                {
                    break;
                }

                Thread.Sleep(100);
            }
            //作弊用!
            //Console.Clear();
            //Console.WriteLine("18853335503");
//红蓝球 彩票程序
            Random a = new Random();
            int lan = a.Next(0,17);

            int[] hong = new int[6];

            int n = 0;
            while (true)
            {
                if (n == 6)
                {
                    break;
                }

                else
                {
                    int b = a.Next(0,34);

                    if (hong.Contains(b))
                    {
                    }
                    else
                    {
                        hong[n] = b;
                        n++;
                    }
                }
            }
            //排序
            for (int i = 0; i < hong.Length - 1; i++)
            {
                for (int j = 0; j < hong.Length - 1 - i; j++)
                {
                    if (hong[j] >= hong[j + 1])
                    {
                        int zj = hong[j + 1];
                        hong[j + 1] = hong[j];
                        hong[j] = zj;
                    }
                }
            }


            Console.WriteLine("蓝球为" + lan);
            Console.WriteLine("红球为:");

            for (int k = 0; k < hong.Length; k++)
            {
                Console.WriteLine(hong[k]);
            }
//去除最高最低分数,求平均分
            Console.WriteLine("请输入评委的人数:");
            int n = Convert.ToInt32(Console.ReadLine());

            if (n >= 5)
            {
                double[] fs = new double[n];

                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine("第{0}个评委的打分:", i + 1);

                    fs[i] = Convert.ToDouble(Console.ReadLine());
                }
                //冒泡排序
                for (int j = 0; j < fs.Length - 1; j++)
                {
                    for (int k = 0; k < fs.Length - 1 - j; k++)
                    {
                        if (fs[k] < fs[k + 1])
                        {
                            double cc = fs[k + 1];
                            fs[k + 1] = fs[k];
                            fs[k] = cc;
                        }
                    }
                }

                double sum = 0;
                for (int m = 0; m < fs.Length; m++)
                {
                    if (m == 0 || m == 1 || m == fs.Length - 1 || m == fs.Length - 2)
                    {
                    }

                    else
                    {
                        sum = sum + fs[m];
                    }
                }
                double avg = sum / (fs.Length - 4);

                Console.WriteLine("该学生的平均分为:" + avg);
            }

            else
            {
                Console.WriteLine("请输入5个及以上评委");
            }
//投票选举
            int[] tp = new int[20];
            int[] ps = new int[5];


            for (int i = 0; i < tp.Length; i++)
            {
                Console.WriteLine("请输入你想投的候选人:(1代表候选人1、2代表候选人2、以此类推)");
                //唱票

                tp[i] = Convert.ToInt32(Console.ReadLine());

                if (tp[i] == 1)
                {
                    ps[0] = ps[0] + 1;
                }
                else if (tp[i] == 2)
                {
                    ps[1] = ps[1] + 1;
                }
                else if (tp[i] == 3)
                {
                    ps[2] = ps[2] + 1;
                }
                else if (tp[i] == 4)
                {
                    ps[3] = ps[3] + 1;
                }
                else if (tp[i] == 5)
                {
                    ps[4] = ps[4] + 1;
                }
            }

            int max = ps[0];
            for (int x = 1; x < ps.Length; x++)
            {
                if (max < ps[x])
                {
                    max = ps[x];
                }
            }


            Console.WriteLine("得票最多的候选人是");
            for (int m = 0; m < ps.Length; m++)
            {
                if (max == ps[m])
                {
                    Console.WriteLine(m + 1);
                }
            }
            Console.WriteLine("最多的票数为" + max);

 

C#_数组

标签:

原文地址:http://www.cnblogs.com/xtxtx/p/4631599.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!