zoukankan      html  css  js  c++  java
  • 2014年10月21日------数组,集合

    //赋给三个人分数
    Console.WriteLine("输入人数");
    int n = int.Parse(Console.ReadLine());
             
    double[,] shuzu = new double[n, 3];
    for (int i = 0; i < n; i++)
     {
        
    Console.WriteLine("输入第" + (i + 1) + "个人的分数");
    Console.WriteLine("输入语文成绩:");
    shuzu[i, 0] = double.Parse(Console.ReadLine());
    Console.WriteLine("输入数学成绩:");
    shuzu[i, 1] = double.Parse(Console.ReadLine());
    Console.WriteLine("输入英语成绩:");
    shuzu[i, 2] = double.Parse(Console.ReadLine());
     }
    

    //定义一个集合,集合是一个类,在System.Collections库中,需要先引用

     rrayList al = new ArrayList();

    //集合如同数组一样,索引从0开始,一个集合最好放一个类型的数据

    int i=al.Add(3);//有值的,object什么数据都能放

    int j=al.Add("孔子");//返回的值是string类型,是添加的数据在集合中的索引

    int k=al.Add(6);//返回的是int类型,是添加的数据在集合中的索引

     

     Console.WriteLine(i+""+""+j+""+k);//读出索引

                Console.ReadKey();

     

     

     

    //定义一个集合,集合是一个类,在System.Collections库中,需要先引用

                ArrayList al = new ArrayList();//集合如同数组一样,索引从0开始,一个集合最好放一个类型的数据

                int i=al.Add(3);//有值的,object什么数据都能放

                int j=al.Add("孔子");

                int k=al.Add(1);

                al.Insert(1,9);//插入到第1个后面9,原来的未知的索引依次靠后一位

                //al.Insert(2,9);//插入到第2个后面9

     

                Console.WriteLine(al[0]);

                Console.WriteLine(al[1]);

                Console.WriteLine(al[2]);

                Console.WriteLine(al[3]);

                //Console.WriteLine(i+""+""+j+""+k);//读出索引

                Console.ReadKey();

     

     

      al.Remove(值是那个索引上的值);//al.removeat();

     

     

    ArrayList al = new ArrayList();//集合如同数组一样,索引从0开始,一个集合最好放一个类型的数据

                int i=al.Add(3);//有值的,object什么数据都能放

                int j=al.Add(5);

                int k=al.Add(1);

                al.Insert(1,9);//插入到第1个后面9,原来的未知的索引依次靠后一位

               

                //al.Remove(3);//删除了上面的第一个索引内的值,3,,,变为了951,

                al.RemoveAt(0);//删除指定的索引上的值。删除了索引0上的值3,变为了951

     

                Console.WriteLine(al[0]);

                Console.WriteLine(al[1]);

                Console.WriteLine(al[2]);

                Console.WriteLine(al[3]);

                //Console.WriteLine(i+""+""+j+""+k);//读出索引

                Console.ReadKey();

    //定义一个集合,集合是一个类,在System.Collections库中,需要先引用
                ArrayList al = new ArrayList();//集合如同数组一样,索引从0开始,一个集合最好放一个类型的数据
                int i=al.Add(3);//有值的,object什么数据都能放
                int j=al.Add(5);
                int k=al.Add(1);
                int c = al.Add(3);//有值的,object什么数据都能放
                int b = al.Add(4);
                
               
              
                int cc=al.Count;//计算出集合里面的数值
                //al.Remove(3);//删除了上面的第一个索引内的值,3,,,变为了5134,只移除第一个出现的3
                //al.RemoveAt(3);//删除指定的索引上的值。删除了索引3上的值3,变为了3534
    
                Console.WriteLine(al[0]);
                Console.WriteLine(al[1]);
                Console.WriteLine(al[2]);
                Console.WriteLine(al[3]);
                Console.WriteLine(al[4]);
                
                Console.WriteLine(cc);//输出5个值
                Console.ReadKey();
    
    
    
    
    
    
    ArrayList al = new ArrayList();
                Console.WriteLine("请输入人数");
                int n = int.Parse(Console.ReadLine());
                for (int i =0; i <n;i++)
                {
                    Console.WriteLine("请输入分数");
                    al.Add(Console.ReadLine());
                }
    
                double sum = 0;
                for(int k=0;k<n;k++)
                {
                sum+=double.Parse(al[k].ToString());
                }
                double avg=sum/n;
    
    
                al.Sort();
                Console.WriteLine("您所输入的数的总分为{0},平均分为{1}",sum,avg);
    
    
                //排序。从小往大
                al.Sort();//对字母或字符串排序,
                for (int d = 0; d < n;d++ )
                {
                    Console.WriteLine(al[d]);
                }
    
    
                Console.ReadLine();
    
     //排序。从大往小
                al.Sort();
                al.Reverse();//反转的功能
                for (int d = 0; d < n;d++ )
                {
                    Console.WriteLine(al[d]);
                }
    
    
                Console.ReadLine();
    ArrayList al = new ArrayList();
                Console.WriteLine("请输入人数");
                int n = int.Parse(Console.ReadLine());
                for (int i =0; i <n;i++)
                {
                    Console.WriteLine("请输入分数");
                    al.Add(Console.ReadLine());
                    //如果是存数字,将来比较大小的时候,需要再添加的时候先转化为数值类型,
                    //在添加到集合里面否则,会当做字符串的编码区比较大小,会出错
                }
    
                double sum = 0;
                for(int k=0;k<n;k++)
                {
                sum+=double.Parse(al[k].ToString());
                }
                double avg=sum/n;
    
    
                Console.WriteLine("您所输入的数的总分为{0},平均分为{1}",sum,avg);
    
                int sy = al.IndexOf("12");//求12的索引,若果输出-1那就是没找到,只返回第一个匹配项的索引
                int sy1 = al.LastIndexOf(“12”);//返回最后一个匹配项的值
                Console.WriteLine("索引为" + sy+"最后的索引为"+sy1);//比较的时候一定要注意数据类型是否相符。否则是比不出
                
                for (int d = 0; d < n;d++ )
                {
                    Console.WriteLine(al[d]);
                }
                Console.ReadLine();
     ArrayList al = new ArrayList();
                Console.WriteLine("请输入人数");
                int n = int.Parse(Console.ReadLine());
                for (int i =0; i <n;i++)
                {
                    Console.WriteLine("请输入分数");
                    al.Add(double.Parse(Console.ReadLine()));
                    //如果是存数字,将来比较大小的时候,需要再添加的时候先转化为数值类型,
                    //在添加到集合里面否则,会当做字符串的编码区比较大小,会出错
                }
                double sum = 0;
                for(int k=0;k<n;k++)
                {
                sum+=double.Parse(al[k].ToString());
                }
                double avg=sum/n;
                Console.WriteLine("您所输入的数的总分为{0},平均分为{1}",sum,avg);
                int sy = al.IndexOf(12.0);//求12的索引,若果输出-1那就是没找到,只返回第一个匹配项的索引
                int sy1 = al.LastIndexOf(12.0);//返回最后一个匹配项的值
                Console.WriteLine("索引为" + sy+"最后的索引为"+sy1);//比较的时候一定要注意数据类型是否相符。否则是比不出
                for (int d = 0; d < n;d++ )
                {
                    Console.WriteLine(al[d]);
                }
    Console.ReadLine();
    

     int[,]sss=new int[3,5]{{99,2,3,4,5},{1,2,3,43,5},{1,2,5,4,58}};
                                        0  1  2 3 4    0 1 2 3   4     0 1 2 3 4         

                                                 0           1            2             

           

    console.write(sss[0.0]);取出来99
    console.write(sss[1.3]);取出来43
    console.write(sss[2.4]);取出来58

  • 相关阅读:
    codeforces 37 E. Trial for Chief【spfa】
    bzoj 1999: [Noip2007]Core树网的核【树的直径+单调队列】
    codehunter 「Adera 6」杯省选模拟赛 网络升级 【树形dp】
    codeforces GYM 100781A【树的直径】
    bzoj 2878: [Noi2012]迷失游乐园【树上期望dp+基环树】
    bzoj 1791: [Ioi2008]Island 岛屿【基环树+单调队列优化dp】
    codeforces 949C
    codeforces 402E
    poj 3613 Cow Relays【矩阵快速幂+Floyd】
    bzoj 2097: [Usaco2010 Dec]Exercise 奶牛健美操【二分+树形dp】
  • 原文地址:https://www.cnblogs.com/9999w/p/4040694.html
Copyright © 2011-2022 走看看