숫자 문제를 맞히는 출제 절차

  #region CLASS-ASK
    public class ASK
    {
        /*
         * N:       
         * _N:  N   
         * num[]:    
         * num[0]    
        */
        private int N,_N;
        private int[] num = {-1,-1,-1,-1,-1};
        private Stopwatch SW = new Stopwatch();
        
        public ASK()
        {
            _N=N = 8;
            Generate();
        }
        public ASK(int times)
        {
            _N=N = times;
            Generate();
        }

        private void Generate()
        {
            Random rand = new Random();
            for (int i = 1; i < 5;i++ )
                do
                {
                    num[i] = rand.Next(0, 10);
                } while (num[i] == num[1 % i] || num[i] == num[2 % i] || num[i] == num[3 % i] || num[i] == num[4 % i]);
            num[0] = num[4];
        }
        public void Reset()
        {
            N = _N;
            Generate();
            SW.Stop();
            SW.Reset();
        }
        public string Compare(string inputStr)
        {
            /*
             *      :
             *     :$INPUTERR
             *        :$OVER+    
             *   :$OK+  
            */
            if (SW.IsRunning)
                SW.Stop();
            string time = SW.Elapsed.Minutes.ToString() + "/'" + SW.Elapsed.Seconds.ToString() + "/"";
            int nA = 0, nB = 0;
            inputStr = inputStr.Trim();
            if(!Regex.IsMatch(inputStr,@"^/d{4}$"))
                return "$INPUTERR";
            int[] input = new int[4];
            for (int i = 0; i < 4;i++)
                Int32.TryParse(inputStr.Substring(i,1),out input[i]);            
            for (int i = 0; i < 4; i++)
            {
                if (input[i]==num[(i+1)%4])
                    ++nA;
                else if (input[i] == num[(i + 2) % 4] || input[i] == num[(i + 3) % 4] || input[i] == num[i % 4])
                    ++nB;
            }
            if (nA == 4)
                return "$OK" + time;
            if (--N == 0)
                return "$OVER" + GetAns();  
            SW.Start();
            return inputStr + "◆" + nA + "A" + nB + "B" + "※  " + N + " " + "〓  " + time;
        }
        private string GetAns()
        {
            StringBuilder SB=new StringBuilder();
            for (int i = 1; i < 5; i++)
                SB.Append(num[i%4].ToString());
            return SB.ToString();
        }
    }
    #endregion

심심해서 놀자고 썼어요.

좋은 웹페이지 즐겨찾기