八旗制问题模拟入队出队

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace 八旗制
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            //实例化数组赋值
            Student stu1 = new Student() { Name = "密码1", Remark = "嗯嗯!" };
            Student stu2 = new Student() { Name = "密码2", Remark = "嗯嗯" };
            Student stu3 = new Student() { Name = "密码3", Remark = "嗯嗯!" };
            Student stu4 = new Student() { Name = "密码5", Remark = "嗯嗯!" };
            Student stu5 = new Student() { Name = "密码6", Remark = "嗯嗯!" };
            Student stu6 = new Student() { Name = "密码7", Remark = "嗯嗯!" };

            Queue<Student> al = new Queue<Student>();

            al.Enqueue(stu1);
            In(stu1);
            al.Enqueue(stu2);
            In(stu2);
            al.Enqueue(stu3);
            In(stu3);
            al.Enqueue(stu4);
            In(stu4);
            al.Enqueue(stu5);
            In(stu5);
            al.Enqueue(stu6);
            In(stu6);

            StringDictionary sd = new StringDictionary();

            while (al.Count > 0)
            {
                var s = al.Dequeue();
                Out(s);
                sd.Add(s.Name, s.Remark);
            }

            int i = 0, j = 0, k = 0;
            foreach (string key in sd.Keys)
            {
                if (sd[key] == "蓝白旗")
                    i++;
                if (sd[key] == "白蓝旗")
                    j++;
                if (sd[key] == "红白旗")
                    k++;


            }
            Console.WriteLine("蓝白旗{0}红白旗{1}白蓝旗{2}", i, k, j);
            Console.Read();
            
            

        }

        //进
        static void In(Student s)
        {
            Console.WriteLine("{0}{1}进入栈道", s.Name, s.Remark);

        }

        static void Out(Student s)
        {
            Console.WriteLine("{0}{1}离开栈道", s.Name, s.Remark);
        }
发布了43 篇原创文章 · 获赞 35 · 访问量 1579

猜你喜欢

转载自blog.csdn.net/qq_45244974/article/details/103716748
今日推荐