zoukankan      html  css  js  c++  java
  • 分队打拳

    6个人,3个人一组。如ABC和WYZ;A不和X对打;C不和Y、Z对打。求3种对打方式;

     class Groups
            {
                public string G1 { get; set; }
                public string G2 { get; set; }
            }
    
            public static void SetGroup()
            {
                string[] group1 = { "A", "B", "C" };
                string[] group2 = { "X", "Y", "Z" };
                List<Groups> listG = new List<Groups>();
                for (int i = 0; i < group1.Length; i++)
                {
                    for (int j = 0; j < group2.Length; j++)
                    {
                        if (group1[i] == "A" && group2[j] == "X")
                        {
                            continue;
                        }
    
                        if (group1[i] == "C" && group2[j] == "Y")
                        {
                            continue;
                        }
                        if (group1[i] == "C" && group2[j] == "Z")
                        {
                            continue;
                        }
                        Groups g = new Groups();
                        g.G1 = group1[i];
                        g.G2 = group2[j];
                        listG.Add(g);
                    }
                }
                ReRanging(listG);
            }
    
            static void ReRanging(List<Groups> listG)
            {
                List<string> tempContainer = new List<string>();
                foreach (var g1 in listG)
                {
                    tempContainer.Clear();
                    tempContainer.Add(g1.G1);
                    tempContainer.Add(g1.G2);
    
                    foreach (var g2 in listG)
                    {
                        if (tempContainer.Contains(g2.G1) || tempContainer.Contains(g2.G2))
                        {
                            continue;
                        }
                        tempContainer.Add(g2.G1);
                        tempContainer.Add(g2.G2);
                    }
                    foreach (var item in tempContainer)
                    {
                        Console.Write(item);
                    }
                    Console.WriteLine();
    
                }
            }
    
      static void Main(string[] args)
            {
                SetGroup();
                Console.ReadKey();
            }

    }
    image

  • 相关阅读:
    Django错误笔记1
    Django学习笔记1 启动及配置一个Django项目
    ubuntu 安装mysqldb
    二叉树 总结
    序列二叉树和反序列 (不是自己做的)
    二叉树的路径
    二叉搜索树的后续遍历
    二叉树层序遍历
    栈的压入 弹出序列
    包含 min的栈
  • 原文地址:https://www.cnblogs.com/potoofly/p/2960685.html
Copyright © 2011-2022 走看看