手機號抽獎

static void Main25手機號抽獎(string[] args)
        {
            //手機號抽獎,本身作的
            Console.WriteLine("請輸入手機號的個數");
            int n =Convert.ToInt32 (Console.ReadLine());
            string[] sj = new string[n];     
            
            
                for (int sjhgs = 0; sjhgs < n; sjhgs++)
                {
                    Console.WriteLine("請輸入手機號");
                    //string sjh = Console.ReadLine();    // 沒用
                    sj[sjhgs] = Console.ReadLine();  //創建一個手機號的數組,用來存放輸入的手機號
                }
                //Console.WriteLine(sjhgs);//輸出手機號
                //for (int i = 0; i < n; i++)
                //{
                //    Console.WriteLine(sj[i]);
                //}            
            DateTime x = DateTime.Now;//當前的時間
            DateTime xx = x.AddSeconds(10);
            while (DateTime.Now.ToString("yyyyMMddHHmmss") != xx.ToString("yyyyMMddHHmmss"))//循環條件是當前時間不等於當前時間加了10秒後的時間
            {
                Console.Clear();
                Random r = new Random();//造一個隨機數生成器
                int gs= r.Next(n);//從n手機號中隨機抽取到手機號gs
                Console.WriteLine(sj[gs]);//輸入抽到的手機號
                Thread.Sleep(1000);     //1秒鐘滾動一次           
            }
          


            //老師版的
            Console.WriteLine("請輸入手機號的個數:");
            int a = Convert.ToInt32(Console.ReadLine());

            string [] sjh = new string [a];

            for (int i = 0; i < a; i++)
            {
                Console.WriteLine("請輸入第{0}個手機號:",i+1);
                sj[i] = Console.ReadLine();
            }

            Console.WriteLine("*************************************");
            // 抽獎
            DateTime d = DateTime.Now;
            DateTime dt = d.AddSeconds(10);

            while (true)
            {
                Console.Clear();
                Random r = new Random();
                int b = r.Next(a);

                Console.WriteLine(sj[b]);
                Thread.Sleep(100);
                if (DateTime.Now.ToString("yyyyMMddHHmmss") == dt.ToString("yyyyMMddHHmmss"))
                {
                    break;
                }
                else
                {
                }

            }

            Console.Clear();//做弊
            Console.WriteLine("15165339515");//


        }
相關文章
相關標籤/搜索