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

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

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

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

  8. Do
  9. $CountF = StringRight($CountF + StringRight(Asc(StringMid($Female, $j, 1)), 2), 2)
  10. $j += 1
  11. Until $j > StringLen($Female)

  12. $Result = 10 * StringRight($CountM - $CountF, 1) + StringRight($CountM + $CountF, 1)
  13. If (StringRight($CountM, 1) < 5 And StringRight($CountF, 1) 9) Then $Result += 1
  14. $Result = 100 - $Result
复制代码
分别为 VB 和 AU3 代码,原理是将文字转换为 ASCII 运算。
可是,当给定的男方和女方是英文时,运算结果相同,但当是中文时,运算结果相差甚远。
发表于 2014-2-11 20:10:36 | 显示全部楼层
[au3]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)[/au3]

试试
发表于 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, 2026-9-22 13:26 , Processed in 0.075062 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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