zoukankan      html  css  js  c++  java
  • 2016/06/29

     1 Stack aa = new Stack();//初始化
     2 aa.Push(1);//向stack集合中添加数据
     3 
     4 
     5 //注意:Stack是没有索引的
     6 //Console.WriteLine(aa[0]);//是错误的
     7 
     8 Console.WriteLine(aa.Peek());//仅用来查看最后一位,不踢出
     9 
    10 //aa.Pop();//弹出,踢出最后一个进入集合的数据
    11 
    12 //Console.WriteLine( aa.Pop());
    13 
    14 int aaa = aa.Count;//统计个数
    15 
    16 aa.Clear();//清空集合
    17 
    18 //Queue 队列集合
    19 //先进的先出,后进的后出
    20 //没有索引
    21 Queue qq = new Queue();
    22 qq.Enqueue(1);//给集合中添加元素
    23 
    24 
    25 qq.Dequeue();//将排在最前面的剔除
    26 int c =qq.Count;//统计个数
    27 
    28 qq.Peek();//只查看,不踢出
    29 
    30 qq.Clear();//清空集合
    31 bool bb =qq.Contains(1);//判断是否包含这个元素,返回值为true or false
    32 
    33 
    34 
    35 ////hashtable 哈希表(先进后出,一个一个赋值,但会一起取值)
    36 ////哈希表集合,一个 位置包含两个值,一个key,一个values
    37 //Hashtable a = new Hashtable();
    38 //a.Add(0,"可口可乐");
    39 //a.Add(1, "雪碧");
    40 //a.Add(2, "芬达");
    41 //a.Add(3, "王老吉");
    42 //a.Add(4, "百事可乐");
    43 //a.Remove(4);//移除王老吉(移除为移除一行)
    44 //IDictionaryEnumerator id = a.GetEnumerator();//枚举类型种的抽取,将key和value分别存于id
    45 //while (id.MoveNext())
    46 //{
    47 // Console.WriteLine(id.Key+"	"+id.Value);//key只代表一个,value亦然。	代表空位符
    48 //}
    49 //foreach (int i in a.Keys)
    50 //{
    51 // Console.WriteLine(i);
    52 //}
    53 //foreach (object b in a.Values)
    54 //{
    55 // Console.WriteLine(b);
    56 //}
    57 //Console.ReadLine();

    函数

     1  ////    public void dayin()
     2         ////{
     3         ////    Console.WriteLine("你好");
     4         ////}
     5         ////public void leijia()
     6         ////{
     7         ////    Console.WriteLine("请输入一个正整数:");
     8         ////    int a = int.Parse(Console.ReadLine());
     9         ////    int sum = 0;
    10         ////    for (int i = 1; i <= a; i++)
    11         ////    {
    12         ////        sum += i;
    13         ////    }
    14         ////    Console.WriteLine(sum);
    15         ////    Console.ReadLine();
    16         ////}
    17         ////private(私人的,只允许当前函数调用)
    18 
    19         ////函数类型
    20         ////第一种如上  没有参数和返回值(void为没有返回值)
    21         ////第二种如下  没有返回值,但是有参数
    22         ////public void leijia(int a)
    23         ////{
    24         ////    int sum = 0;
    25         ////    for (int i = 1; i <= a; i++)
    26         ////    {
    27         ////        sum += i;
    28         ////    }
    29         ////    Console.WriteLine(sum);
    30         ////    Console.ReadLine();
    31  
    32         ////}
    33         ////第三种 有返回值和参数(下文中有用才写有返回值)
    34         ////public int leijia1(int b)
    35         ////{
    36         ////    int sum = 0;
    37         ////    for (int i = 1; i <= b; i++)
    38         ////    {
    39         ////        sum += i;
    40         ////    }
    41         ////    return sum;
    42         ////}
    43         ////第四种 有返回值没参数
    44         ////public int leijia2()
    45         ////{
    46         ////    Console.WriteLine("请输入一个正整数:");
    47         ////    int a = int.Parse(Console.ReadLine());
    48         ////    int sum = 0;
    49         ////    for (int i = 1; i <= a; i++)
    50         ////    {
    51         ////        sum += i;
    52         ////    }
    53         ////    return sum;
    54         ////}

    实际应用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Collections;
    
    namespace _629做题
    {
        class Program
        {
            public void ljqjc()
            {
              Console.WriteLine("请输入您想累加阶乘到多少:");
              int a =int.Parse(Console.ReadLine());
              int sum = 0;
              int x =1;
              for (int i = 1; i <= a; i++)
              {
                  x *= i;
                  sum += x;
              }
              Console.WriteLine(sum);
              Console.ReadLine();
            }
            public void ljqjc(int a)
            {
                int sum = 0;
                int x = 1;
                for (int i = 1; i <= a; i++)
                {
                    x *= i;
                    sum += x;
                }
                Console.WriteLine(sum);
                Console.ReadLine();
     
            }
            public int ljqjc1()
            {
                Console.WriteLine("请输入您想累加阶乘到多少:");
                int a = int.Parse(Console.ReadLine());
                int sum = 0;
                int x = 1;
                for (int i = 1; i <= a; i++)
                {
                    x *= i;
                    sum += x;
                }
                return sum;
    
            }
            public int ljqjc1(int a)
            {
                int sum = 0;
                int x = 1;
                for (int i = 1; i <= a; i++)
                {
                    x *= i;
                    sum += x;
                }
                return sum;
    
            }
            public void fuck()
        {
                 Console.Write("请输入班级人数:");
                 int a = int.Parse(Console.ReadLine());
                 ArrayList jh=new ArrayList();
                 int sumy = 0;
                 int sums = 0;
                 for (int i = 0; i < a; i++)
                 {
                     Console.WriteLine("请输入第{0}个人的姓名:",i+1);
                     jh.Add(Console.ReadLine());
                     Console.WriteLine("请输入第{0}个人的语文成绩:",i+1);
                     jh.Add(Console.ReadLine());
                     Console.WriteLine("请输入第{0}个人的数学成绩:",i+1);
                    jh.Add(Console.ReadLine());
                     Console.WriteLine("请输入第{0}个人的英语成绩:",i+1);
                     jh.Add(Console.ReadLine());
                     
                 }
                 for (int i = 3; i < a * 4; i = i + 4)
                 {
                     for (int j = i; j < a * 4 - 4; j = j + 4)
                      {
                         if (int.Parse(jh[i].ToString()) < int.Parse(jh[j + 4].ToString()))
                        {
     
                             int huan = int.Parse(jh[i].ToString());
                             jh[i] = int.Parse(jh[j + 4].ToString());
                             jh[j + 4] = huan;
                             string o = jh[i - 3].ToString();
                             jh[i - 3] = jh[j + 1];
                             jh[j + 1] = o;
                         }
                     }
                 }
               for (int i = 1; i < a * 4; i = i + 4)
                 {
                     sumy += int.Parse(jh[i].ToString());
                     sums += int.Parse(jh[i+1].ToString());
      
                 }
                Console.WriteLine("语文总分为:"+sumy);
                 Console.WriteLine("数学平均分为;" + sums/a);
                 Console.WriteLine("英语最高分的人为:"+jh[0]+"最高分为:"+jh[3]);
                Console.ReadLine();
        }
            public void fuck(int a)
            {
                ArrayList jh = new ArrayList();
                int sumy = 0;
                int sums = 0;
                for (int i = 0; i < a; i++)
                {
                    Console.WriteLine("请输入第{0}个人的姓名:", i + 1);
                    jh.Add(Console.ReadLine());
                    Console.WriteLine("请输入第{0}个人的语文成绩:", i + 1);
                    jh.Add(Console.ReadLine());
                    Console.WriteLine("请输入第{0}个人的数学成绩:", i + 1);
                    jh.Add(Console.ReadLine());
                    Console.WriteLine("请输入第{0}个人的英语成绩:", i + 1);
                    jh.Add(Console.ReadLine());
    
                }
                for (int i = 3; i < a * 4; i = i + 4)
                {
                    for (int j = i; j < a * 4 - 4; j = j + 4)
                    {
                        if (int.Parse(jh[i].ToString()) < int.Parse(jh[j + 4].ToString()))
                        {
                            int huan = int.Parse(jh[i].ToString());
                            jh[i] = int.Parse(jh[j + 4].ToString());
                            jh[j + 4] = huan;
    
                            string o = jh[i - 3].ToString();
                            jh[i - 3] = jh[j + 1];
                            jh[j + 1] = o;
                        }
                    }
                }
                for (int i = 1; i < a * 4; i = i + 4)
                {
                    sumy += int.Parse(jh[i].ToString());
                    sums += int.Parse(jh[i + 1].ToString());
    
                }
                Console.WriteLine("语文总分为:" + sumy);
                Console.WriteLine("数学平均分为;" + sums / a);
                Console.WriteLine("英语最高分的人为:" + jh[0] + "最高分为:" + jh[3]);
                Console.ReadLine();
            }
    
            static void Main(string[] args)
            {
                Program hs = new Program();
                Console.Write("请输入班级人数:");
                int a = int.Parse(Console.ReadLine());
                hs.fuck(a);
    
            }
        }
    }

    上面的代码里的函数有些主函数里没用,因为我主要是实验,不同形式的函数的用法,之前已经用来测试过了。

  • 相关阅读:
    html5 表單元素
    html5 表單輸入類型
    html5 服務器發送事件
    html5 web workers
    html5應用緩存
    html5 sessionStorage VS loaclStorage
    html5地理定位
    html5 画布和SVG的差别
    html5 SVG
    SQL-22 统计各个部门对应员工涨幅的次数总和,给出部门编码dept_no、部门名称dept_name以及次数sum
  • 原文地址:https://www.cnblogs.com/blueteasama/p/5627453.html
Copyright © 2011-2022 走看看