问答详情
源自:6-1 练习题目

各位大佬请帮我简化下我的代码,感觉有些复杂

 static void Main(string[] args)
        {
            //声明 两组数组 ;
            int[] score =new int[]{89,90,98,86,60,91,93,85};
            string[] name = new string []{"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
            //声明 分数中的 最大值;
            int max = score[0];
            //判断出了最大的分数;
            for (int i =0;i<score.Length;i++)
            {
                max =max>score[i]?max:score[i];

            }
            //现在要判断出分数的拥有者,即分数在数组中的具体位置
             for(int j = 0;j<score.Length;j++)
             {
                 if(max == score[j])
                 {
                    Console.Write("分数最高的是"+ name[j]+ ",分数是"+max);
                   
                 }
             }
   
        }


提问者:罪恶倾城 2018-09-17 15:38

个回答

  • 慕莱坞2375072
    2018-09-17 19:59:00
    已采纳

     static void Main(string[] args)
            {
                //声明两组数组 ;
                int[] score =new int[]{89,90,98,86,60,91,93,85};
                string[] name = new string []{"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
                //声明分数中的最大值和得分者;
                int max = 0;

                string topName = null;
                //判断出了最大的分数;
                for (int i =0;i<score.Length;i++)
                {
                    if (score[i]>max)

                    max =score[i];

                    topName = name[i];

                }
                        Console.Write("分数最高的是{0},分数是{1}", topName, max);//输入结果
                       
        }


  • 微风拂过v
    2018-10-14 14:01:34

    static void Main(string[] args)
            {
                //声明两组数组 ;
                int[] score =new int[]{89,90,98,86,60,91,93,85};
                string[] name = new string []{"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
                //声明分数中的最大值和得分者;
                int max = 0;

                string topName = null;
                for (int i =0;i<score.Length;i++)   //判断出了最大的分数;            {
                    if (score[i]>max)

                  {

                    max =score[i];

                    topName = name[i];

                   }

                }
                        Console.Write("分数最高的是{0},分数是{1}", topName, max);//输入结果
                        
        }


  • 慕斯卡7915457
    2018-10-13 17:18:52

                int[] num =new int[8]{89, 90, 98, 56, 60, 91, 93, 85 };

                string[] name = new string[8] { "吴松", "钱东宇", "伏晨", "陈陆", "周蕊", "林日鹏", "何昆", "关欣" };

                int max = 0;

                for (int i = 0; i < num.Length; i++)

                {

                    max = num[max] > num[i] ? max : i;

                }

                Console.WriteLine("分数最高的是{0},分数是{1}",name[max],num [max]);