|
写了个茶馆对诗的机器人,发现老比别人慢,大家看下,有没有更好的办法.谢谢。
poem是CMUD数据库的View和column名称
^茶博士提笔在墙上写道:(*)
- poem=%1
- #math words %len(@poem)
- word1=%left(@poem,2)
- word2=%right(%left(@poem,4),2)
- word3=%right(%left(@poem,6),4)
- array1=%find(@word1,poem,poem)
- array2=%find(@word2,poem,poem)
- array3=%find(@word3,poem,poem)
- i=%numitems(@array1,poem,poem)
- j=%numitems(@array2,poem,poem)
- k=%numitems(@array3,poem,poem)
- a=1
- #while (@a<=@i)
- {
- #variable b 1
- #while (@b<=@j)
- {
- #if (%item(@array1,@a)=%item(@array2,@b))
- {
- //#sh A: @a %item(@array1,@a) B:@b %item(@array2,@b)
- temp=%additem(%item(@array1,@a),@temp)
- }
- #math b @b+1
- }
- #math a @a+1;
- }
- a=1
- #while (@a<=@i)
- {
- #variable b 1
- #while (@b<=@k)
- {
- #if (%item(@temp,@a)=%item(@array3,@b))
- {
- //#sh A: @a %item(@temp,@a) B:@b %item(@array3,@b)
- temp2=%additem(%item(@temp,@a),@temp2)
- }
- #math b @b+1
- }
- #math a @a+1;
- }
- #variable answer %db(@temp2,poem)
- #if (%len(@answer)<=@words)
- {
- answer @answer
- } {
- #math a %len(@answer)/2;
- answer2=%left(@answer,@a)
- answer3=%right(@answer,@a)
- #if (%pos(@word1,@answer2)>0) {answer @answer2} {answer @answer3}
- }
- temp=""
- temp2=""
复制代码
[ 本帖最后由 killunix 于 2009-10-21 12:11 AM 编辑 ] |
|