分队打拳

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

原文地址:https://www.cnblogs.com/potoofly/p/2960685.html