题库 题库

【简答题】

 
Option Base 1
Dim s As String
Private Sub Command1_Click()
  Open App.Path & "\in5.dat" For Input As #1
  s = Input(LOF(1), #1)
  Close #1
End Sub
Private Sub Command2_Click()
  Dim n As Integer, t As String, word_num As Integer
  n = Len(s): t = ""
  For i = 1 To n
      c = Mid(s, i, 1)
      If c <> " " Then
        t = t + c
      Else
        If foundhuiwen(t) Then
            word_num = word_num + 1
        End If
        t = ""
      End If
  Next i
  Text1.Text = word_num
End Sub
'以下Function 过程用于判断字符串是否为回文
Function foundhuiwen(p As String)
  '考生编写

参考答案

  foundhuiwen = True
  k = Len(p)
  For i = 1 To k / 2
      If Mid(p, i, 1) <> Mid(p, k + 1 - i, 1) Then
        foundhuiwen = False
        Exit For
      End If
  Next
End Function
Private Sub Form_Unload(Cancel As Integer)
    Open App.Path & "\out5.dat" For Output As #1
    Print #1, Text1.Text
    Close #1
End Sub

相关试题