• 0906小练习


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

    namespace 练习0906
    {
    class Program
    {
    struct student
    {
    public int num;
    public string code;
    public string name;
    public decimal score;
    }
    public string pdc(string a)
    {
    if (a != null)
    { return a; }
    else
    { return "f";}
    }
    public string pdn(string a)
    {
    if (a != null)
    { return a; }
    else
    { return "f"; }
    }
    public decimal pds(decimal a)
    {
    if (a>=0&&a<=100)
    { return a; }
    else
    { return -1; }
    }
    static void Main(string[] args)
    {
    Program hanshu=new Program();
    ArrayList st = new ArrayList();
    student student =new student();
    Console.Write("请输入班级人数:");
    int n = int.Parse(Console.ReadLine());
    int num = 1;
    for (int i = 0; i < n; i++)
    {
    student.num = num;
    Console.Write("请输入第" + (i + 1) + "个学生的学号:");
    student.code=Console.ReadLine();
    for (; ; )
    {
    if (hanshu.pdc(student.code) == "f")
    {
    Console.Write("序号不能为空,请重新输入第" + (i + 1) + "个学生的学号:");
    student.code = Console.ReadLine();
    }
    else
    {
    break;
    }
    }
    Console.Write("请输入第" + (i + 1) + "个学生的名字:");
    student.name=Console.ReadLine();
    for (; ; )
    {
    if (hanshu.pdn(student.name) == "f")
    {
    Console.Write("姓名不能为空,请重新输入第" + (i + 1) + "个学生的名字:");
    student.name = Console.ReadLine();
    }
    else
    {
    break;
    }
    }
    Console.Write("请输入第" + (i + 1) + "个学生的成绩:");
    try
    {
    student.score = decimal.Parse(Console.ReadLine());
    for (; ; )
    {
    if (hanshu.pds(student.score) == -1)
    {
    Console.Write("成绩输入有误,请重新输入第" + (i + 1) + "个学生的成绩:");
    student.score = decimal.Parse(Console.ReadLine());
    }
    else
    {
    break;
    }
    }
    }
    catch { Console.WriteLine("成绩输入必须为数字!"); }
    num++;
    st.Add(student);
    Console.WriteLine("-------------------------------");
    }
    Console.Write("输入完毕请按回车键打印学生信息:");
    Console.ReadLine();
    for (int i = 0; i < n-1; i++)
    {
    for (int j = i+1; j < n; j++)
    {
    student a = (student)(st[i]);
    student b = (student)(st[j]);
    if (a.score< b.score)
    {
    object zhong = st[i];
    st[i] = st[j];
    st[j] = zhong;
    }
    }
    }
    Console.WriteLine("==============学生成绩展示=================");
    Console.WriteLine("序号" + " "+" "+"学号"+" "+" "+"姓名" + " "+" "+"成绩");
    for (int i = 0; i < n;i++)
    {
    student a = (student)(st[i]);
    Console.Write(a.num);Console.Write(" ");Console.Write(" ");
    Console.Write(a.code);Console.Write(" ");Console.Write(" ");
    Console.Write(a.name);Console.Write(" ");Console.Write(" ");
    Console.Write(a.score);Console.Write(" ");Console.Write(" ");
    Console.WriteLine();
    }
    Console.ReadLine();
    }
    }
    }

  • 相关阅读:
    [BZOJ1211]:[HNOI2004]树的计数(prufer序列)
    [CSP-S模拟测试]:那一天她里我而去(堆优化Dijkstra)
    [CSP-S模拟测试]:那一天我们许下约定(DP+组合数学)
    BZOJ3130 [Sdoi2013]费用流 【网络流 + 二分】
    BZOJ3124 [Sdoi2013]直径 【树的直径】
    BZOJ3122 [Sdoi2013]随机数生成器 【BSGS】
    BZOJ2707 [SDOI2012]走迷宫 【概率dp + tarjan + 高斯消元】
    BZOJ2726 [SDOI2012]任务安排 【斜率优化 + cdq分治】
    洛谷P2351 [SDOi2012]吊灯 【数学】
    BZOJ2246 [SDOI2011]迷宫探险 【记忆化搜索dp + 概率】
  • 原文地址:https://www.cnblogs.com/xiaobao5161/p/5845166.html
Copyright © 2020-2023  润新知