2010年10月22日 星期五

笨小猴

內容:
笨小猴的詞彙量很小,所以每次做英語選擇題的時候都很頭疼。 但是他找到了一種方法,經試驗證明,用這種方法去選擇選項的時候選對的機率非常大!
這種方法的具體描述如下:假設maxn是單詞中出現次數最多的字母的出現次數,minn是單詞中出現次數最少的字母的出現次數,如果maxn-minn是一個質數,那麼笨小猴就認為這是個Lucky Word,這樣的單詞很可能就是正確的答案。
輸入說明:
輸入只有一行,是一個單詞,其中只可能出現小寫字母,並且長度小於100
輸出說明:
輸出共兩行,第一行是一個字符串,假設輸入的的單詞是Lucky Word,那麼輸出“Lucky Word”,否則輸出“No Answer”;
第二行是一個整數,如果輸入單詞是Lucky Word,輸出maxn-minn的值,否則輸出0
範例輸入:
範例1: error
範例2: olymipic  
範例輸出:
範例1: Lucky Word 2
範例2: No Answer 0
提示:

單詞error中出現最多的字母r出現了3次,出現次數最少的字母出現了1次,3-1=22是質數。


單詞olymipic中出現最多的字母i出現了2次,出現次數最少的字母出現了1次,2-1=11不是質數。

2 則留言:

  1. Dim MaxM As Integer, MinM As Integer, strAL As String
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    strAL = "abcdefghijklmnopqrstuvwxyz"
    Do While Not EOF(1)
    Line Input #1, strQ
    MaxM = 1
    MinM = 99
    For i = 1 To 26
    K = Mid(strAL, i, 1)
    Mx = 0
    For j = 1 To Len(strQ)
    L = Mid(strQ, j, 1)
    If K = L Then
    Mx = Mx + 1
    End If
    Next j
    If MaxM < Mx Then MaxM = Mx
    If MinM > Mx And Mx <> 0 Then MinM = Mx
    Next i
    N = MaxM - MinM
    Call isP(N)
    Loop
    Close #2
    Close #1
    End
    End Sub
    Public Sub isP(ByVal N As Long)
    If N = 1 Then
    Print #2, "No Answer 0"
    Exit Sub
    End If
    For i = 2 To N ^ 0.5
    If N Mod i = 0 And N <> 2 Then
    Print #2, "No Answer 0"
    Exit Sub
    End If
    Next i
    Print #2, "Lucky Word " & N
    End Sub

    by 小白

    回覆刪除
  2. Dim ans As Boolean
    Public Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do Until EOF(1)
    ReDim st(100) As String
    ReDim stnum(100) As Integer
    Line Input #1, stri
    n = 1: k = Len(stri)
    Do Until n = k + 1
    ans = False: Min = 99: Max = 0
    step = Left(stri, 1)
    stri = Right(stri, Len(stri) - 1)
    For i = 1 To n
    If step = st(i) Then
    stnum(i) = stnum(i) + 1
    ans = True
    Exit For
    End If
    Next i
    If ans = False Then st(n) = step: stnum(n) = stnum(n) + 1
    n = n + 1
    Loop
    For i = 1 To n
    If Max < stnum(i) Then Max = stnum(i)
    If Min > stnum(i) Then Min = stnum(i):
    Next i
    If Min = 0 Then Min = 1
    ansm = Max - Min: ans = True
    For i = 2 To ansm - 1
    If ansm Mod i = 0 Then
    ans = False
    Exit For
    End If
    Next i
    If ansm = 0 Or ansm = 1 Then ans = False
    If ansm = 2 Then ans = True
    If ans = True Then
    Print #2, "Lucky Word " & ansm
    Else
    Print #2, "no answers" & " 0"
    End If
    Loop
    Close #2
    Close #1
    End Sub
    BY ㄚ揚

    回覆刪除