Exemplo n.º 1
0
        private void Move()
        {
            //pickup three cups
            CupChain cc = CurrentCup.RemoveNext(3);

            //select destination cup
            int destinationCupNumber = CurrentCup.Number - 1;

            if (destinationCupNumber < 1)
            {
                destinationCupNumber = CupMax;
            }
            while (cc.Contains(destinationCupNumber))
            {
                destinationCupNumber--;
                if (destinationCupNumber < 1)
                {
                    destinationCupNumber = CupMax;
                }
            }

            //place picked cups
            Cup destinationCup = OrderedCupList[destinationCupNumber - 1];

            destinationCup.InsertChain(cc);

            //select current cup
            CurrentCup = CurrentCup.Next;
        }
Exemplo n.º 2
0
 public void Fill2()
 {
     for (int i = 10; i <= 1000 * 1000; i++)
     {
         Cup cup = new Cup(i);
         CupList.Add(cup);
     }
     CupMax = CupList.Max(x => x.Number);
 }
Exemplo n.º 3
0
        public string GetResult2()
        {
            Cup  cup1 = OrderedCupList[0].Next;
            Cup  cup2 = cup1.Next;
            long val1 = cup1.Number;
            long val2 = cup2.Number;

            return($"{val1 * val2}");
        }
Exemplo n.º 4
0
 public Data2(string inputData)
 {
     foreach (char c in inputData)
     {
         Cup cup = new Cup(c - '0');
         CupList.Add(cup);
     }
     CupMax = CupList.Max(x => x.Number);
 }
Exemplo n.º 5
0
        internal void InsertChain(CupChain cc)
        {
            Cup nextTmp = Next;

            Next             = cc.StartCup;
            cc.StartCup.Prev = this;
            nextTmp.Prev     = cc.EndCup;
            cc.EndCup.Next   = nextTmp;
        }
Exemplo n.º 6
0
        public void Link()
        {
            for (int i = 0; i < CupList.Count - 1; i++)
            {
                CupList[i].Next     = CupList[i + 1];
                CupList[i + 1].Prev = CupList[i];
            }
            CupList[0].Prev = CupList[CupList.Count - 1];
            CupList[CupList.Count - 1].Next = CupList[0];

            CurrentCup     = CupList[0];
            OrderedCupList = CupList.OrderBy(x => x.Number).ToList();
        }
Exemplo n.º 7
0
        public string GetResult1()
        {
            StringBuilder sb  = new StringBuilder();
            Cup           c   = OrderedCupList[0];
            Cup           tmp = c.Next;

            while (tmp != c)
            {
                sb.Append(tmp.Number);
                tmp = tmp.Next;
            }
            return(sb.ToString());
        }
Exemplo n.º 8
0
        public void PrintNext(Cup cup)
        {
            Cup tmp = cup;

            Console.Write(tmp.Number);
            tmp = tmp.Next;
            while (tmp != cup)
            {
                Console.Write(tmp.Number);
                tmp = tmp.Next;
            }
            Console.WriteLine();
        }
Exemplo n.º 9
0
        public bool Contains(int num)
        {
            Cup tmp = StartCup;

            while (tmp != EndCup)
            {
                if (tmp.Number == num)
                {
                    return(true);
                }
                tmp = tmp.Next;
            }
            return(EndCup.Number == num);
        }
Exemplo n.º 10
0
        public void PrintCups(int index)
        {
            Cup startCup = CurrentCup;

            for (int i = 0; i < index; i++)
            {
                startCup = startCup.Prev;
            }
            Console.Write(startCup.Number);
            Cup tmp = startCup.Next;

            while (tmp != startCup)
            {
                Console.Write(tmp.Number);
                tmp = tmp.Next;
            }
            Console.WriteLine();
            return;
        }
Exemplo n.º 11
0
        public void PrintPrev(Cup cup)
        {
            Cup tmp = cup;

            Console.Write(tmp.Number);
            tmp = tmp.Prev;
            StringBuilder sb = new StringBuilder();

            while (tmp != cup)
            {
                sb.Append(tmp.Number);
                tmp = tmp.Prev;
            }
            var arr = sb.ToString().ToCharArray();

            Array.Reverse(arr);
            string rev = new string(arr);

            Console.WriteLine(rev);
        }