• c#复习-1


     1 using System;
     2 using System.Collections.Generic;
     3 using System.Collections;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace ConsoleApplication1
     9 {
    10     class Program
    11     {
    12         struct student               //结构体
    13         {
    14             public int xuhao;
    15             public string xuehao;       //学号
    16             public string name;      // 姓名
    17             public decimal fenshu;   //分数
    18 
    19         }
    20         static void Main(string[] args)
    21         {
    22             //添加5个学生的信息到集合中,
    23             //每个学生都有:学号,姓名,成绩,3个内容
    24             //添加完毕后将学生的分数从高到低排列并打印出来
    25 
    26             //请输入第1个学生的学号:101
    27             //请输入第1个学生的姓名:xxx
    28             //请输入第1个学生的成绩:99
    29             //------------------------(注意加个分割线)
    30             //请输入第2个学生的学号:102
    31             //请输入第2个学生的姓名:xxx
    32             //请输入第2个学生的成绩:98
    33             //....一直到第5个输入完,然后按回车
    34             //第1个学生的学号:101,姓名:xxx:成绩:99
    35             //第2个学生....
    36             //第3个..
    37             //每段都加个分割线
    38 
    39             //1、循环添加学生信息
    40             ArrayList list = new ArrayList();
    41 
    42             for (int i = 1; i < 6; i++)
    43             {
    44                 student stu = new student(); //实例化
    45 
    46                 Console.Write("请输入第" + i + "个学生的学号:");
    47                 stu.xuehao = Console.ReadLine();
    48                 Console.Write("请输入第" + i + "个学生的姓名:");
    49                 stu.name = Console.ReadLine();
    50                 Console.Write("请输入第" + i + "个学生的成绩:");
    51                 stu.fenshu = Convert.ToDecimal(Console.ReadLine());
    52                 stu.xuhao = i;
    53 
    54                 list.Add(stu);
    55                 Console.WriteLine("===============================");
    56             }
    57 
    58             Console.WriteLine("------------------------成绩排序--------------------------");
    59 
    60             //2、排序
    61 
    62             for (int i = 0; i < list.Count - 1; i++)
    63             {
    64                 for (int j = i + 1; j < list.Count; j++)
    65                 {
    66                     student stu1 = (student)list[i];
    67                     student stu2 = (student)list[j];
    68 
    69                     if (stu1.fenshu < stu2.fenshu)
    70                     {
    71                         Object ob = list[i];
    72                         list[i] = list[j];
    73                         list[j] = ob;
    74                     }
    75                 }
    76             }
    77 
    78             //3、打印
    79             foreach (object o in list)
    80             {
    81                 student ss = (student)o;
    82                 Console.WriteLine("" + ss.xuhao + "个学生的学号:" + ss.xuehao + ",姓名:" + ss.name + ",分数:" + ss.fenshu + "");
    83             }
    84 
    85 
    86 
    87 
    88             Console.ReadLine();
    89 
    90 
    91         }
    92     }
    93 }

  • 相关阅读:
    CCF CSP 201509-1 数列分段
    CCF CSP 201503-1 图像旋转 (降维)
    CCF CSP 201412-1 门禁系统
    CCF CSP 201409-1 相邻数对
    CCF CSP 201403-1 相反数
    CCF CSP 201312-1 出现次数最多的数
    Win10环境下 HTTP 错误 500.19
    牛客网 整数拆分 (动态规划)
    牛客网 放苹果
    LeetCode9 回文数
  • 原文地址:https://www.cnblogs.com/tonyhere/p/5592201.html
Copyright © 2020-2023  润新知