public class Solution
    {
        private string M1(int A, int B)
        {
            StringBuilder sb = new StringBuilder();
            int groupA = A / 2;
            int freeA = A % 2;
            int temp = groupA;
            int distance = B - groupA;
            for (int i = 0; i < groupA; i++)
            {
                if (temp > 0)
                {
                    sb.Append("AA");
                    if (distance > 0 && B > 0)
                    {
                        sb.Append("BB");
                        B = B - 2;
                    }
                    else if (distance <= 0 && B > 0)
                    {
                        sb.Append("B");
                        B = B - 1;
                    }
                    else//distance < 0
                    {
                        sb.Append("");
                    }
                    distance--;
                }
                else
                {
                    sb.Append("A");
                }
                temp--;
            }
            if (freeA != 0)
            {
                sb.Append("A");
            }
            while (B > 0)
            {
                sb.Append("B");
                B--;
            }
            return sb.ToString();
        }

        private string Change(string str)
        {
            str = str.Replace("A", "C");
            str = str.Replace("B", "A");
            str = str.Replace("C", "B");
            return str;
        }

        public string StrWithout3a3b(int A, int B)
        {
            var result = "";
            if (A >= B)
            {
                result = M1(A, B);
            }
            else
            {
                result = M1(B, A);
                result = Change(result);
            }
            return result.ToLower();
        }
    }

 

posted on 2019-01-28 14:53  Sempron2800+  阅读(120)  评论(0编辑  收藏  举报