作者dragondoll (龙娃娃)
看板mud_sanc
标题Re: [wizs] 巫师升等测验题目四
时间Thu Nov 20 20:19:22 2008
程式位置: /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