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);
}
八旗制問題模擬入隊出隊
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.