zoukankan      html  css  js  c++  java
  • 二维数组与集合

    //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();

    //输入班级人数,将每个人的姓名放进集合,然后全部读取
    //ArrayList name = new ArrayList();
    //Console.Write("请输入班级人数:");
    //int n = int.Parse(Console.ReadLine());
    //for (int i = 0; i < n; i++)
    //{
    // Console.Write("请输入第{0}个人的姓名:",i+1);
    // name.Add(Console.ReadLine());
    //}
    //Console.WriteLine("所有人员姓名输入完毕,请按回车键读取!");
    //Console.ReadLine();

    ////foreach 遍历集合
    //foreach (object aa in name)
    //{
    // Console.Write(aa+" ");
    //}

    //Console.ReadLine();

    //object a;
    //int b = 4;
    //a = b;
    //double c = 3.14;
    //a = c;
    //bool d = true;
    //a = d;
    //string e = "Hello";
    //a = e;
    //DateTime dt = DateTime.Now;
    //a = dt;


    //输入班级人数,输入每个人的姓名、语数英成绩进入集合
    //求语文的总分,数学的平均分,
    //英语的最高分的人的姓名及所有科目的分数(冒泡排序)
    //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();

  • 相关阅读:
    【JZOJ6271】【NOIP提高组A】锻造 (forging)
    【JZOJ6272】【NOIP提高组A】整除 (division)
    【JZOJ3397】【GDOI2014模拟】雨天的尾巴
    input绑定datapicker控件后input再绑定blur或者mouseout等问题
    解决每次打开office 2010显示正在配置的问题
    Ext JS treegrid 发生的在tree上增加itemclick 与在其它列上增加actioncolumn 发生事件冲突(event conflict)的解决办法
    Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法
    本地同时启动两个tomcat
    转: ExtJS中xtype一览
    web前端基础知识及快速入门指南
  • 原文地址:https://www.cnblogs.com/yx1314520/p/5719530.html
Copyright © 2011-2022 走看看