查看单个帖子
旧 2009-08-06   #4
shuieryin
中级会员
级别:2 | 在线时长:16小时 | 升级还需:14小时级别:2 | 在线时长:16小时 | 升级还需:14小时
 
shuieryin 的头像
 
注册: 07年02月20日
帖子: 257
声望力: 21
声望: 10 shuieryin 闻道则喜
现金:24两梁山币
资产:24两梁山币
致谢数: 0
获感谢文章数:0
获会员感谢数:0
回复: [抛砖引玉] 中文数字转换罗马数字机器人

checkNum = 0
correctNum = 1
tmp = %2
chatName = %1
showNum = @tmp
#math tmpCount {%len( @tmp) / 2}
tmpLen = %len( @tmp)
#loop 1,@tmpCount {
#math tmpLen {@tmpLen - 2}
tmpNum = %db( @convertChineseNum, %left( @tmp, 2))
#addkey tmpNumList {%i} {@tmpNum}
@tmp = %rightback( @tmp, @tmpLen)
}
#loopdb @tmpNumList {
#if %val>99 {
#math lastPos {%key - 1}
#math nextPos {%key + 1}
lastNum = %db( @tmpNumList, @lastPos)
nextNum = %db( @tmpNumList, @nextPos)
#if %val=10000 {
#math lastTwoPos {%key - 2}
lastTwoNum = %db( @tmpNumList, @lastTwoPos)
#if @lastNum!=10 {#math checkNum {@checkNum * %val}}
#unvar lastTwoPos
#unvar lastTwoNum
} {#math checkNum {@checkNum + @lastNum*%val}}
#if @nextNum>9 {#if @nextNum!=10000 {correctNum = 0}}
#unvar lastPos
#unvar nextPos
#unvar lastNum
#unvar nextNum
}
#if %val=0 {
#math nextPos {%key + 1}
nextNum = %db( @tmpNumList, @nextPos)
#math nextTwoPos {%key + 2}
nextTwoNum = %db( @tmpNumList, @nextTwoPos)
#if @nextTwoNum<10 {#math checkNum {@checkNum + @nextNum}}
#if @nextTwoNum=10000 {#math checkNum {@checkNum + @nextNum}}
#if @nextNum>9 {correctNum = 0}
#unvar nextPos
#unvar nextNum
#unvar nextTwoPos
#unvar nextTwoNum
}
#if %val=10 {
#math lastPos {%key - 1}
#math nextPos {%key + 1}
lastNum = %db( @tmpNumList, @lastPos)
nextNum = %db( @tmpNumList, @nextPos)
#if !@lastNum {#if @nextNum!=10000 {#math checkNum {@checkNum + %val + @nextNum}} {#math checkNum {%val * @nextNum}}} {#if @nextNum!=10000 {#math checkNum {@checkNum + @lastNum*%val + @nextNum}} {#math checkNum {(@checkNum + @lastNum*%val) * @nextNum}}}
#if @nextNum>9 {#if @nextNum!=10000 {correctNum = 0}}
#unvar lastPos
#unvar nextPos
#unvar lastNum
#unvar nextNum
}
#if %key=@tmpCount {
#if %val<10 {
#math lastPos {%key - 1}
lastNum = %db( @tmpNumList, @lastPos)
#if @lastNum<10 {#if @lastNum>0 {correctNum = 0}}
#unvar lastPos
#unvar lastNum
}
}
#if @tmpCount=1 {checkNum = %db( @tmpNumList, %key)}
}
#if @correctNum=0 {chat %1, 数字错误:@showNum} {chat %1, 数字为: @checkNum}
#unvar tmpNumList
#unvar checkNum
#unvar correctNum
#unvar tmp
#unvar chatName
#unvar showNum
#unvar tmpLen
#unvar tmpCount
#unvar tmpNum
shuieryin 当前离线  
回复时引用此帖