Re: [問題] 1-42取出6+1個數字
【 在 Pistachi.bbs@mobbs.stut.edu.tw () 的大作中提到: 】
: 創一個LinkedList 把所有數字丟進去
: 再隨機抓出來就好...
: LinkedList list=new LinkedList();
: Random r= new Random();
: for(int i=0;i<=42;i++){
: list.add(new Integer(i));
: }
: for(int i=0;i<6;i++){
: System.out.println(
: ((Integer)list.get(r.nextInt(list.size()))).intValue()
: );
: }
: 好長的一行啊 XD
這樣子還是會重複呀,要不重複的話應該把 list.get() 改成 list.remove()
另外前面已經有版友提到可以使用 Set,不過那篇好像沒轉進 ptt
如果是使用 Set 的話,只需要不斷重複將數字放進 Set
並且判斷 Set size 是否為你需要的數字數量即可
--
NPDA - Non-deterministic PushDown Automata
(不確定是否推倒自動機)
DPDA - Deterministic PushDown Automata
(確定會推倒自動機)
得証: DPDA 效率比較高
※ 來源:‧資訊傳奇 inf.csie.thu.edu.tw‧[FROM: 220-131-153-63.HINET-IP.hinet.]
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 13 之 21 篇):