• 7.28


    int[] shu = new int[] { 1,2,3};
    //二维数组
    int [,] array = new int[4,2];
    //4,表示有四个一维数组
    //2,表示每一个一维数组有2个元素
    int[,] shuzu = new int[,]
    {
    {1,2},
    {3,4},
    {5,6},
    {7,8}
    };
    for (int i = 0; i < 4; i++)
    {
    for (int j = 0; j < 2; j++)
    {
    Console.Write(shuzu[i,j]+" ");
    }
    }

    打印出来一个“王”这个字
    string[,] wang = new string[,]
    {
    {" ","■","■","■","■","■"," "},
    {" "," "," ","■"," "," "," "},
    {" "," "," ","■"," "," "," "},
    {" "," ","■","■","■"," "," "},
    {" "," "," ","■"," "," "," "},
    {" "," "," ","■"," "," "," "},
    {"■","■","■","■","■","■","■"}
    };
    for (int i = 0; i < 7; i++)
    {
    for (int j = 0; j < 7; j++)
    {
    Console.Write(wang[i,j]);
    }
    Console.WriteLine();
    }

    打印出每个人的语数英成绩
    Console.Write("请输入班级人数:");
    int n = int.Parse(Console.ReadLine());
    double[,] score = new double[n, 3];
    for (int i = 0; i < n; i++)
    {
    Console.Write("请输入第{0}个人的语文成绩:",i+1);
    score[i, 0] = double.Parse(Console.ReadLine());
    Console.Write("请输入第{0}个人的数学成绩:", i + 1);
    score[i, 1] = double.Parse(Console.ReadLine());
    Console.Write("请输入第{0}个人的英语成绩:", i + 1);
    score[i, 2] = double.Parse(Console.ReadLine());
    }
    Console.WriteLine("所有人的语数英成绩输入完毕,请按回车键打印!");
    Console.ReadLine();
    for (int i = 0; i < n; i++)
    {
    Console.WriteLine("第{0}个人的语文成绩是{1},数学成绩{2},英语成绩{3}。",i+1,score[i,0],score[i,1],score[i,2]);
    }
    //求语文总分
    double sum = 0;
    for (int i = 0; i < n; i++)
    {
    sum += score[i, 0];
    }
    Console.WriteLine(sum);
    Console.ReadLine();


    //多维数组
    //int[, ,] shuzu = new int[4, 3, 2];
    ////4,表示有四个二维数组
    ////3,表示每个二维数组里面有3个1维数组
    ////2,表示每个1维数组里面有2个元素

    //string[, ,] gao = new string[3, 4, 1]
    // {
    // {
    // {"张三"},{"李四"},{"王五"},{"赵六"}
    // },
    // {
    // {"冯七"},{"王八"},{"张全蛋"},{"小沈阳"}
    // },
    // {
    // {"刘能"},{"赵四"},{"赵本山"},{"岳云鹏"}
    // }
    // };

    //split 分离
    //一次性接收姓名、年龄、工作单位
    //Console.Write("请输入您的姓名、年龄、工作单位(**-**-**):");
    //string quan = Console.ReadLine();
    //string[] array = quan.Split('-');
    //for (int i = 0; i < array.Length; i++)
    //{
    // Console.WriteLine(array[i]);
    //}
    //Console.ReadLine();

    {
    ArrayList al = new ArrayList();//初始化
    al.Add(5);
    al.Add(3);
    al.Add(6);
    al.Add(4);
    al.Add(1);
    al.Add(2);
    al.Add("2");
    al.Add("hello");
    al.Add(true);
    al[3] = "你好";
    al.Clear(); 移除所有元素
    ArrayList al1 = new ArrayList();
    al1 = (ArrayList)al.Clone();//克隆
    //判断是否包含
    Console.WriteLine(al1.Contains("2"));
    //获取第一次出现该元素的索引号
    Console.WriteLine(al1.IndexOf(11));
    //获取最后一次出现该元素的索引号
    Console.WriteLine(al1.LastIndexOf(2));
    //插入某个索引位置某个元素
    al.Insert(2,"Hello");

    //移除某个第一次出现的元素
    al.Remove("hello");
    //移除某个索引位置的元素
    al.RemoveAt(3);

    al.Sort();//排序 ,升序
    al.Reverse();//翻转整个集合
    Console.WriteLine(al[2]);
    Console.WriteLine(al.Count);
    Console.ReadLine();


    //输入班级人数,输入每个人的姓名、语数英成绩进入集合
    //求语文的总分,数学的平均分,
    //英语的最高分的人的姓名及所有科目的分数(冒泡排序)
    //0 姓名 4 8 12
    //1 语文成绩5 9 13
    //2 数学成绩6 10 14
    //3 英语成绩7 11 15
    Console.Write("请输入班级人数:");
    int n = int.Parse(Console.ReadLine());
    double yu = 0;
    double shu = 0;
    ArrayList al = new ArrayList();
    for (int i = 0; i < n; i++)
    {
    Console.Write("请输入第{0}个人的姓名:",i+1);
    al.Add(Console.ReadLine());
    Console.Write("请输入第{0}个人的语文成绩:",i+1);
    al.Add(double.Parse(Console.ReadLine()));
    yu += double.Parse(al[al.Count - 1].ToString());
    Console.Write("请输入第{0}个人的数学成绩:", i + 1);
    al.Add(double.Parse(Console.ReadLine()));
    shu += double.Parse(al[al.Count - 1].ToString());
    Console.Write("请输入第{0}个人的英语成绩:", i + 1);
    al.Add(double.Parse(Console.ReadLine()));
    }
    Console.WriteLine("所有信息输入完毕,请按回车键继续!");
    Console.ReadLine();
    Console.WriteLine("语文的总分是:"+yu);
    Console.WriteLine("数学的平均分是:"+(shu/n));

    for (int i = 3; i < 4*n-1; i+=4)
    {
    for (int j = i; j < 4 * n - 4; j += 4)
    {
    if (double.Parse(al[i].ToString()) < double.Parse(al[j + 4].ToString()))
    {
    //换姓名
    object zhong = al[i - 3];
    al[i - 3] = al[j + 1];
    al[j + 1] = zhong;
    //换语文
    zhong = al[i - 2];
    al[i - 2] = al[j + 2];
    al[j + 2] = zhong;
    //换数学
    zhong = al[i - 1];
    al[i - 1] = al[j + 3];
    al[j + 3] = zhong;
    //换英语
    zhong = al[i];
    al[i] = al[j + 4];
    al[j + 4] = zhong;
    }
    }
    }
    Console.WriteLine("英语最高分的学生是{0},英语分数是{1},语文分数是{2},数学分数{3}",al[0],al[3],al[1],al[2]);
    Console.ReadLine();

  • 相关阅读:
    2020-11-15(第十一周)助教周小结
    2020-11-08(第十周)助教周小结
    2020-11-01助教周小结(第九周)
    Template.
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    OO第一单元总结
    AFO
    Codeforces Round #424 (Div. 2)
  • 原文地址:https://www.cnblogs.com/power8023/p/5720133.html
Copyright © 2020-2023  润新知