找回密码
 加入
搜索
查看: 3071|回复: 5

[效率算法] 缘分小程序,VB 和 AU3 结果不同

  [复制链接]
发表于 2014-2-11 17:44:18 | 显示全部楼层 |阅读模式
Dim countM As Integer
Dim countF As Integer
countM = 0
countF = 0
i = 1
Do
    countM = Abs(Right(countM - Right(Asc(Mid(txtM.Text, i, 1)), 2), 2))
    i = i + 1
Loop Until i > Len(txtM.Text)
i = 1
Do
    countF = Right(countF + Right(Asc(Mid(txtF.Text, i, 1)), 2), 2)
    i = i + 1
Loop Until i > Len(txtF.Text)
result = 10 * Right(countM - countF, 1) + Right(countM + countF, 1)
If Right(countM, 1) < 5 And Right(countF, 1) <> 9 Then result = result + 1
result = 100 - result
Local $CountM = 0, $CountF = 0
 Local $i = 1, $j = 1
 Local $Result

Do
 $CountM = Abs(StringRight($CountM - StringRight(Asc(StringMid($Male, $i, 1)), 2), 2))
 $i += 1
 Until $i > StringLen($Male)

Do
 $CountF = StringRight($CountF + StringRight(Asc(StringMid($Female, $j, 1)), 2), 2)
 $j += 1
 Until $j > StringLen($Female)

$Result = 10 * StringRight($CountM - $CountF, 1) + StringRight($CountM + $CountF, 1)
 If (StringRight($CountM, 1) < 5 And StringRight($CountF, 1) 9) Then $Result += 1
 $Result = 100 - $Result
分别为 VB 和 AU3 代码,原理是将文字转换为 ASCII 运算。
可是,当给定的男方和女方是英文时,运算结果相同,但当是中文时,运算结果相差甚远。
发表于 2014-2-11 20:10:36 | 显示全部楼层
Local $CountM = 0, $CountF = 0
 Local $i = 1, $j = 1
 Local $Result
$Male="什么"
$Female="什么"

For $i=1 To StringLen($Male)
If Asc(StringMid($Male, $i, 1))<127 Then
$CountM = Abs(StringRight($CountM - StringRight(Asc(StringMid($Male, $i, 1)), 2), 2))
Else
$CountM = Abs(StringRight($CountM - StringRight(Asc(StringMid($Male, $i, 1)), 2), 2))        
        $bin=StringToBinary(StringMid($Male, $i, 1))
        $CountM = Abs(StringRight($CountM - StringRight(Dec(Hex(BinaryMid($bin,2,1))), 2), 2))
EndIf        
Next

For $j=1 To StringLen($Female)
If Asc(StringMid($Female, $i, 1))<127 Then        
$CountF = StringRight($CountF + StringRight(Asc(StringMid($Female, $j, 1)), 2), 2)
Else
        $CountF = StringRight($CountF + StringRight(Asc(StringMid($Female, $j, 1)), 2), 2)
        $bin2=StringToBinary(StringMid($Female, $i, 1))
        $CountF = Abs(StringRight($CountF - StringRight(Dec(Hex(BinaryMid($bin2,2,1))), 2), 2))
        EndIf
Next




$Result = 10 * StringRight($CountM - $CountF, 1) + StringRight($CountM + $CountF, 1)
 If (StringRight($CountM, 1) < 5 And StringRight($CountF, 1)<>9) Then $Result += 1
 $Result = 100 - $Result
 MsgBox(0,"",$Result)


试试
发表于 2014-2-12 07:05:06 | 显示全部楼层
vb的用ascw获取ascii值试下
 楼主| 发表于 2014-2-12 19:58:21 | 显示全部楼层
试试
gto250 发表于 2014-2-11 20:10



依旧不行。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2014-2-17 09:41:09 | 显示全部楼层
遇到这种问题,我通常比较笨的办法就是在每个计算值后都加个msgbox,看看计算出来的结果是不是我预期的结果,如果不是的话就好找问题了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 14:50 , Processed in 0.082760 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表