zoukankan      html  css  js  c++  java
  • C#第十三节课

    冒泡排序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace shuzufuxi
    {
    class Program
    {
    static void Main(string[] args)
    {


    //Console.WriteLine("请输入人数:");
    //int n = int.Parse(Console.ReadLine());
    //string[] name = new string[n+1];
    //string[] t = new string[n+1];
    //for (int i = 1; i <= n;i++ )
    //{

    // Console.Write("请输入第" + i + "个人的名字:");
    // name[i] = Console.ReadLine();
    // Console.Write("请输入他的手机号:");
    // t[i] = Console.ReadLine();
    // Console.Write("输入成功!");
    // Console.ReadLine();
    // Console.Clear();
    // }
    //Random ran=new Random();
    //int a=0;
    //string s=null;
    //for (; ; )
    //{
    // for (int j = 0; ; j++)
    // {
    // Console.Clear();
    // a = ran.Next(n + 1);
    // Console.WriteLine(name[a] + ":" + t[a]);
    // System.Threading.Thread.Sleep(100);
    // if (j==10)
    // {
    // Console.WriteLine(name[a] + ":" + t[a]);
    // Console.ReadLine();
    // break;
    // }
    // }
    //}

    //冒泡排序 从大到小排列
    //int[] shuzu = new int[] { 3, 1, 8, 4, 0, 5, 6 };
    //8134056
    //8314056
    //


    //foreach (int a in shuzu)
    //{
    // Console.WriteLine(a);
    //}

    //object //所有类的基类,可以接受任何数据类型

    Console.Write("请输入人数:");
    int n = int.Parse(Console.ReadLine());
    string [] name=new string[n];
    double[] cj = new double[n];
    double sum = 0;
    for (int i = 0; i < n; i++)
    {
    Console.Clear();
    Console.Write("请输入第" + (i + 1) + "个人的名字:");
    name[i] = Console.ReadLine();
    Console.Write("请输入第"+(i+1)+"个人的成绩:");
    cj[i] = double.Parse(Console.ReadLine());
    Console.WriteLine("输入成功");
    System.Threading.Thread.Sleep(300);
    }
    Console.Clear();
    string y;
    double x = 0;
    for (int j = 0; j < (n-1); j++)
    {
    for (int m = 0; m < (n - j-1); m++)
    {
    if (cj[m] > cj[m+1])
    {
    x = cj[m];
    cj[m] = cj[m+1];
    cj[m+1] = x;
    y = name[m];
    name[m] = name[m + 1];
    name[m + 1] = y;
    }
    }
    }
    Console.WriteLine("成绩由低到高排列顺序为:");
    //foreach (double e in cj)
    //{

    // Console.WriteLine(e);
    //}
    for (int r = 0; r < n; r++)
    {
    Console.WriteLine(name[r]+":"+cj[r]);
    }
    for (int z = 1; z < (n - 1); z++)
    {

    sum += cj[z];
    }

    Console.WriteLine("平均成绩为:"+(sum/(n-2)));
    Console.WriteLine("最低成绩为:" + cj[0]);
    Console.WriteLine("最高成绩为:" + cj[n-1]);

    Console.ReadLine();

    }
    }
    }

  • 相关阅读:
    设计模式3.1 Abstract Factory(抽象工厂)对象创建型模式
    设计模式文本编辑器
    Jquery调用webService远程访问出错的解决方法
    重构列表
    设计模式3.创建型模式
    设计模式 3.2 Builder(生成器)对象创建型模式
    设计模式 3.4 Prototype(原型)对象创建模式
    设计模式3.3 Factory Method(工厂方法) 对象创建型模式
    C# Word.Office操作总结
    设计模式 3.5 Singleton(单件)对象创建型模式
  • 原文地址:https://www.cnblogs.com/xiongxiaobai/p/5271480.html
Copyright © 2011-2022 走看看