• 年度单身舞会队列


    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    
    namespace TestOfQueueDancers
    {
        class Program
        {
            static void Main(string[] args)
            {
                Queue males = new Queue();
                Queue females = new Queue();
                
                FormLines(males,females);
                StartDancing(males,females);
    
                if (males.Count > 0 || females.Count > 0)
                {
                    HeadOfLine(males,females);
                }
    
                NewDancers(males,females);
    
                if (males.Count > 0 || females.Count > 0)
                {
                    HeadOfLine(males,females);
                }
    
                NewDancers(males,females);
                Console.WriteLine("Press Enter");
    
            }
    
            static void NewDancers(Queue male, Queue female)
            {
                Dancer m, w;
                m = new Dancer();
                w = new Dancer();
    
                if (male.Count > 0 && female.Count > 0)
                {
                    m.GetName(male.Dequeue().ToString());
                    w.GetName(female.Dequeue().ToString());
                }
                else if ((male.Count > 0) && (female.Count == 0))
                {
                    Console.Write("Wating for female dancer.");
                }
                else if ((female.Count > 0) && (male.Count == 0))
                {
                    Console.Write("Wating for male dancer.");
                }
            }
    
            public static void HeadOfLine(Queue male, Queue female)
            {
                Dancer w, m;
                w = new Dancer();
                m = new Dancer();
    
                if (male.Count > 0)
                {
                    m.GetName(male.Peek().ToString());
                }
                if (female.Count > 0)
                {
                    w.GetName(female.Peek().ToString());
                }
    
                if (!string.IsNullOrEmpty(m.name) &&
                    !string.IsNullOrEmpty(w.name))
                {
                    Console.WriteLine("Next in line are:" + m.name + "\t" + w.name);
                }
                else
                {
                    if (!string.IsNullOrEmpty(m.name))
                    {
                        Console.WriteLine("Next in line is:" + m.name);
                    }
                    else
                    {
                        Console.WriteLine("Next in line is:" + w.name);
                    }
                }
            }
    
            public static void StartDancing(Queue male, Queue female)
            {
                Dancer m, w;
                m = new Dancer();
                w = new Dancer();
                Console.WriteLine("Dance partners are:");
    
                Console.WriteLine();
                for (int i = 0; i < 4; i++)
                {
                    m.GetName(male.Dequeue().ToString());
                    w.GetName(female.Dequeue().ToString());
    
                    Console.WriteLine(w.name + "\t" + m.name);
                }
            }
    
            public static void FormLines(Queue male, Queue female)
            {
                Dancer d = new Dancer();
                StreamReader inFile;
                inFile = File.OpenText("dancers.dat");
                string line;
                while (inFile.Peek() != -1)
                {
                    line = inFile.ReadLine();
                    d.sex = line.Substring(0, 1);
                    d.name = line.Substring(2, line.Length - 2);
    
                    if (d.sex == "M")
                    {
                        male.Enqueue(d);
                    }
                    else
                    {
                        female.Enqueue(d);
                    }
                }
    
                
            }
        }
    
        public struct Dancer
        {
            public string name;
            public string sex;
    
    
            public override string ToString()
            {
                return name;
            }
    
            public void GetName(string n)
            {
                name = n;
            }
        }
    }


    dancers.dat文件类容:

    F Jennifer Ingram
    M Frank Optiz
    M Terrill Beckerman
    M Mike Dahly
    F Beata Lovelace
    M Raymond Williams
    F Beth Munson
    M Don Gundolf
    F Bernica Tackett
    M David Durr
    M Mike McMillan
    F Nikki Feldman


  • 相关阅读:
    UVA 12697 Minimal Subarray Length
    学渣乱搞系列之后缀数组
    HDU 3518 Boring counting
    NYOJ 832 合并游戏
    如何在SAP里创建configurable material物料主数据
    在Kubernetes上运行SAP UI5应用(下): 一个例子体会Kubernetes内容器的高可用性和弹性伸缩
    使用SAP C4C rule editor动态控制UI上某个按钮是否显示
    ABAP SICF服务和Java Servlet的比较
    一些SAP Partners能够通过二次开发实现打通C/4HANA和S/4HANA的方法介绍
    Java实现的有道云笔记图片批量下载工具
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671520.html
Copyright © 2020-2023  润新知