首页 新闻 会员 周边 捐助

各位大帮帮手用VB编写

0
悬赏园豆:10 [已关闭问题]
<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;" lang="EN-US"><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;" lang="EN-US"></span></p>
jayue2005的主页 jayue2005 | 初学一级 | 园豆:85
提问于:2009-11-21 22:00
< >
分享
其他回答(2)
0

 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

woody.wu | 园豆:3621 (老鸟四级) | 2009-11-21 22:32
0

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;

}

dege301 | 园豆:2825 (老鸟四级) | 2009-11-21 22:46
0

 If str = Strings.StrReverse(str) Then

                Console.WriteLine("回文")

            Else

                Console.WriteLine("不是回文")

  End If

 

StrReverse 字符串反转函数!

zqonline | 园豆:193 (初学一级) | 2009-11-24 12:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册