• c# 集合


    -----------------------------------------------------------------集合
     ArrayList al = new ArrayList();
                    al.Add(3);//从末位开始添加
                    al.Add(5);
                    al.Add(7);
                    al.Add(7);
                    al.Add(11);
                    al.Add(13);
                    al.Insert(1,9);//插入
                    //al.Remove(7);//只能删一个
                    al.RemoveAt(5);//删索引
                    Console.WriteLine(al.IndexOf(7));//输出第一个7的索引
                    Console.WriteLine(al.LastIndexOf(7));//输出最后一个7的索引
                    if (al.Contains(5))//包含
                    {
                         Console.WriteLine(al.IndexOf(5));
                    }
                    for (int i = 0; i <al.Count ; i++)//al的长度count
                    {
                        Console.WriteLine(al[i]);
                    }

    ------------------------------------------------------
     
                    Console.WriteLine("请输入人数:");
                    int n = Convert.ToInt32(Console.ReadLine());
                    ArrayList al = new ArrayList();
                    double sum = 0,p=0;
                    for (int i = 0; i < n; i++)
                    {
                         Console.WriteLine("请输入第"+(i+1)+"个人的分数:");
                         double x = Convert.ToDouble(Console.ReadLine());
                         al.Add(x);
                         sum = sum + x;
                    }

                    p = sum / n;
                 
                   Console.Write("平均分:" +p + " "+"总分:" +sum+ " ");
                    for (int i = 0; i < n; i++)
                    {
                         if (Convert.ToInt32( al[i])<=60)
                         {
                          Console.Write("第"+(i+1)+"个不及格,分数:"+al[i]+" ");
                         }
                     
                      
                    }
                    Console.WriteLine();
                    foreach (var item in al)
                    {
                        Console.Write(item + " ");
                    }
                    Console.WriteLine();
                        al.Sort();//排序
                   
                
                    for (int i = 0; i < al.Count; i++)
                    {
                        Console.Write(al[i] + " ");
                    }
                    Console.WriteLine();
                    al.Reverse();
                    foreach (var item in al)
                    {
                        Console.Write(item + " ");
                    }

    ----------------------------------------------stack 集合  先进后出
      Stack ss = new Stack();
                    ss.Push(1);
                    ss.Push(2);
                    ss.Push(3);
                    ss.Push(4);
                    ss.Push(5);
                    foreach (var item in ss)
                    {
                        Console.WriteLine(item);//先进后出;无索引
                    }
                    Console.WriteLine("有"+ss.Count+"个元素");
                    for (int i = 0; i < 2; i++)
                    {
                        string m = ss.Pop().ToString();
                    Console.WriteLine("tanchu元素wei"+m);
                    }
                    //ss.Clear();
                    Stack cl = (Stack)ss.Clone();
                    Console.WriteLine("有" + cl.Count + "个元素");

                    string n = ss.Peek().ToString();
                    Console.WriteLine("最后一个进入元素为" + n);


                    Console.ReadKey();

    ------------------------------------------------------------queue集合  先进先出

     Queue q = new Queue();
                    q.Enqueue(1);//tianjia
                    q.Enqueue(2);
                    q.Enqueue(5);
                    q.Enqueue(7);
                    q.Enqueue(9);
                    foreach (var item in q)
                    {
                        Console.WriteLine(item);
                    }
                    Console.WriteLine("有" + q.Count + "个元素");
                    int xc = int.Parse(q.Dequeue().ToString());//yichu
                    Console.WriteLine("移除第一个元素" +xc);
                    foreach (var item in q)
                    {
                        Console.WriteLine(item);
                    }
                    Console.WriteLine("剩" + q.Count + "个元素");
                    int dq = int.Parse(q.Peek().ToString());//duqu
                    Console.WriteLine("duqu元素" + dq);

                    bool c = q.Contains(7);//判断q集合里面有没有7
                    Console.WriteLine("q集合里面有7:" + c);

                    Console.ReadKey();
    -------------------------------------------------------------------哈希表  先进后出


    Hashtable h = new Hashtable();
                    double sum = 0, pj;
                    int m = 0;
                    h.Add("王一",80);
                    h.Add("李一",90);
                    h.Add("张一",56);
                    h.Add("杨一", 100);
                    h.Add("田一", 74);
                    h.Add("罗一", 60);
                   // for (int i = 0; i < h.Count; i++)
                  
                   
                    foreach (var i in h.Values)
                    {
                         sum = sum + Convert.ToDouble( i);
                        if (Convert.ToDouble( i)<60)
                        {
                            m++;
                           
                            Console.WriteLine("不及格分数是"+i);
                        }
                    }
                   
                    pj = sum / h.Count;
                    Console.Write("平均分:" + pj + " " + "总分:" + sum + " ");
                    Console.WriteLine("不及格的有" +m + "个");
    ---------------------------------------------------------------用ArrayList

      ArrayList a = new ArrayList();
                    double sum = 0, pjf = 0;
                    int m = 0;
                    //a.Add("王一");
                    //a.Add(80);
                    //a.Add("李一");
                    //a.Add(30);
                    //a.Add("张一");
                    //a.Add(87);
                    //a.Add("王五");
                    //a.Add(50);
                    //a.Add("杨一");
                    //a.Add(100);
                    //a.Add("刘一");
                    //a.Add(70);
                    //a.Add("罗一");
                    //a.Add(60);
                    Console.WriteLine("请输入您要录入的人数:");
                    int n = Convert.ToInt32(Console.ReadLine());
                    for (int i = 0; i < n; i++)
                    {
                        Console.WriteLine("请输入您要录入的人的姓名:");
                        a.Add(Console.ReadLine());
                        Console.WriteLine("请输入您要录入的分数:");
                    a.Add(Convert.ToDouble(Console.ReadLine()));
                    }
                   
                    for (int i = 1; i <= a.Count; i+=2)
                    {
                       sum=sum+Convert.ToDouble( a[i]);
                       if (Convert.ToDouble( a[i])<60)
                       {
                            m++;
                            Console.WriteLine("不及格人有" +a[i-1]);
                            Console.WriteLine("不及格分数是" + Convert.ToDouble(a[i]));
                       }

                    }

                    pjf = 2*sum /a.Count ;
                    Console.Write("平均分:" + pjf + " " + "总分:" + sum + " ");
                    Console.WriteLine("不及格的有" + m + "个");

                    Console.ReadKey();

    -----------------------------------------------------用Hashtable

     Hashtable h = new Hashtable();
                    
                    double sum = 0, pj;
                    int m = 0;
                    //h.Add("王一", 80);
                    //h.Add("李一", 90);
                    //h.Add("张一", 56);
                    //h.Add("杨一", 100);
                    //h.Add("田一", 74);
                    //h.Add("罗一", 60);
                    Console.WriteLine("请输入您要录入的人数:");
                    int n = Convert.ToInt32(Console.ReadLine());
                    for (int i = 0; i < n; i++)
                    {

                        ArrayList a = new ArrayList();
                        Console.WriteLine("请输入您要录入的人的姓名:");
                        a.Insert(0,Console.ReadLine());
                        Console.WriteLine("请输入您要录入的分数:");
                        a.Insert(1,Convert.ToDouble(Console.ReadLine()));
                        sum = sum + Convert.ToDouble(a[1]);
                        h.Add(i,a);
                    }
                      pj = sum / h.Count;
                    Console.Write("平均分:" + pj + " " + "总分:" + sum + " ");
                    foreach (ArrayList item in h.Values)
                    {
                      
                        if (Convert.ToDouble(item) < 60)
                        {
                            m++;

                            Console.WriteLine("不及格的有"+item[0]+"分数是" + item[1]);
                        }
                    }

                 
                    Console.WriteLine("不及格的有" + m + "个");


    ------------------------------------------------------------------------------------

  • 相关阅读:
    四瓶化学试剂合成了人工生命
    DNA 就是软件代码
    首例人造生命,碱基对达到100多万个
    看到一个新闻管理系统,看上去开源,其实是骗你使用
    日本可合成碱基对 遗传信息"无中生有"
    新生命如何在实验室“被创造”
    一个基因有多少碱基对
    A、T、G、C四个字母(构成碱基的基本单位)的不同排列,画出一张基因图谱
    远程图片下载不能显示的问题
    30亿个碱基对组成,分布在细胞核的23对染色体中
  • 原文地址:https://www.cnblogs.com/lovesy2413/p/4322830.html
Copyright © 2020-2023  润新知