老哥的其中一個面試題目
做法似乎有很多,不過還是要寫寫看
畢竟c#已經離我有點久遠了
高不高效我不知道,至少他跑得出來就偷笑了 XDDDDDD
做法似乎有很多,不過還是要寫寫看
畢竟c#已經離我有點久遠了
這是題目 Write a high performance program to shuffle the poker card.
using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class globalvar { public static ArrayList sufflecard = new ArrayList(); public static ArrayList allcard = new ArrayList(); public static string[] match = new string[] {"K","A","2","3","4","5","6","7","8","9","10","J","Q"}; } class Program { static void Main(string[] args) { for (int i = 1; i <=52; i++) { globalvar.allcard.Add(i); } shuffle(); Console.WriteLine("done!"); Console.ReadLine(); } private static void shuffle() { Random locate = new Random(); while (globalvar.allcard.Count!=0) { int randomnum = locate.Next(globalvar.allcard.Count); int sufflenum = Convert.ToInt32(globalvar.allcard[randomnum]); globalvar.allcard.RemoveAt(randomnum); globalvar.sufflecard.Add(sufflenum); int 花色 = sufflenum/13; int 點數位置 = sufflenum%13; string 點數 = globalvar.match[點數位置]; switch (花色) { case 0: Console.WriteLine("黑桃"+點數); break; case 1: Console.WriteLine("紅心"+點數); break; case 2: Console.WriteLine("磚塊" + 點數); break; case 3: Console.WriteLine("梅花" + 點數); break; default: break; } } Console.WriteLine(globalvar.sufflecard.Count+"張卡已洗好,剩餘"+globalvar.allcard.Count+"張"); } } }
高不高效我不知道,至少他跑得出來就偷笑了 XDDDDDD
留言
張貼留言