为了账号安全,请及时绑定邮箱和手机立即绑定

各位大帮帮手用VB编写

各位大帮帮手用VB编写

陪伴而非守候 2018-10-25 05:06:47
<p class="MsoNormal" style="text-indent: -21pt; margin: 0cm 0cm 0pt 21pt; mso-char-indent-count: -1.5;"><span style="font-family: 宋体; font-size: 14pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman';">判断回文。如果一个字符串正反读字符顺序都相同,称之为回文,例如,</span><span style="font-size: 14pt;"><span style="font-family: Times New Roman;">level,madam</span></span><span style="font-family: 宋体; font-size: 14pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman';">。编制一个程序,输入任意一个字符串,判断它是否为回文字符串。</span><span style="font-size: 14pt;"></span></p>
查看完整描述

2 回答

?
呼唤远方

TA贡献1856条经验 获得超11个赞

Function Check(ByVal str As String) As Boolean
        Dim re As Boolean = True
        Dim length As Integer
        length = str.Length
        Dim mid As Integer
        mid = Math.Floor(length / 2)
        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim k As Integer = 0
        Dim firstStr As String
        Dim lastStr As String
        If length Mod 2 <> 0 Then
            For i = 0 To mid
                j = i
                k = mid * 2 - i
                firstStr = str(j)
                lastStr = str(k)
                If firstStr <> lastStr Then
                    re = False
                    Exit For
                End If
            Next
        Else
            re = False

        End If
        Return re
    End Function


查看完整回答
反对 回复 2018-10-30
?
繁花不似锦

TA贡献1851条经验 获得超4个赞

vb的语法忘了,我用.net些吧

char[] ch=str.ToChar();

bool b=false;

if(ch.length\2!=0)

{

  for(int i=0;i<=(ch.length-1)/2;i++)

{

  if(ch[i]==ch[ch.length-1-i])

{

b=true;

continue;

}

else

{

b=false;

break;

}

}

return b;

}


查看完整回答
反对 回复 2018-10-30
  • 2 回答
  • 0 关注
  • 252 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信