Re: [wizs] 巫師升等測驗題目四

看板mud_sanc (Sanctuary - 聖殿)作者 (龍娃娃)時間17年前 (2008/11/20 20:19), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
程式位置: /u/d/dragondoll/question/q4.c 程式行數: 反正是更小的程式。 執行結果: 照樣略 這題花了我和別人聊天聊到沒在算的時間寫的。 反正本題非常的作業用,花最多的時間是在Ctrl CV。 inherit ROOM; mixed abc = ({ "a", "b", "b", "c", "c", "c" }); mapping mp=([]); void create() { ::create(); seteuid(getuid()); set("light",1); set("short","Test3"); set("long",@PLAIN PLAIN ); } void init() { add_action("test41","test41"); add_action("test42","test42"); add_action("test43","test43"); add_action("test44","test44"); add_action("test45","test45"); add_action("test46","test46"); } int test41(string str) { string msg; int haha=0,i; msg = "你所尋找的內容在陣列中第"; for(i=0;i<sizeof(abc);i++) { if(str==abc[i]) { msg = msg + (i+1) + " "; haha=1; } } if(haha==1) write(msg + "項\n"); else write("在陣列中並無此內容\n"); return 1; } int test42(string str) { if(member_array(str,abc)<0)return notify_fail("陣列中無此元素\n"); else { abc = abc - ({str}); } write("陣列中的元素已被刪除, 目前陣列為: " + identify(abc)+"\n"); return 1; } int test43(string str) { abc = abc + ({str}); write("已為陣列補上新資料, 目前陣列為: " + identify(abc)+"\n"); return 1; } int test44(string str) { int i; i = atoi(str); if(i<=0)return notify_fail("格式不合!\n"); else if(sizeof(abc)<i)return notify_fail("你所欲刪除的目標超過陣列大小 \n"); else { abc = abc[0..i-2]+abc[i..sizeof(abc)-1]; } write("陣列中的第"+i+"已被刪除, 目前陣列為: " + identify(abc)+"\n"); return 1; } int test45(string str) { int i; mp = ([]); for(i=0;i<sizeof(abc);i++) { mp[abc[i]] = mp[abc[i]] + 1; } write("重組後的映射為: " + identify(mp)+"\n"); return 1; } int test46(string str) { mixed bb; bb = keys(mp); bb = sort_array(bb,1); write("排序後的映射Keys為: " + identify(bb)+"\n"); return 1; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.194.152.155
文章代碼(AID): #199LNB1I (mud_sanc)
文章代碼(AID): #199LNB1I (mud_sanc)