2012年11月20日 星期二

英文造句

請設計一個英文造句的程式,能將輸入的一些名詞,動詞(名詞及動詞的輸入順序是隨機)組成一些簡單句型。
所謂簡單句型是
主詞+及物動詞+受詞.
注意規則: 
a.當主詞是He, She, Mary, John時,動詞要加s.
b.當主詞和受詞是同一類人稱代名詞時,受詞要改成反身代名詞。
I -- me -- myself
He/John -- him -- himself
She/Mary -- her -- herself
They -- them -- themselves 
本題造句所需用到的主詞、動詞、受詞全部列出如下:
主詞: I、He、She、They、Mary、John
及物動詞: love、like、see、find
受詞:me、him、her、them、Mary、John
輸入規範
輸入檔案中第一列為一個正整數n,代表有n個英文造句練習。其後n列,每一列為一個英文造句練習,每一列有一個主詞、一個受詞、一個動詞(其順序是隨機),各個英文字之間以一個或多個空白分隔。注意:n 100。
輸出規範
輸出n列,每一列為一個英文造句之答案。若某個練習中,有多個造句是合於文法的,則需全部在同一列印出,且兩個英文句子之間需印出"或"這個字以示區隔。
輸入範例(test7.txt)
5
I her love
I love her
Mary love John
them see I
love I me
輸出範例(result7.txt)
I love her.
I love her.
Mary loves John. 或 John loves Mary.
I see them.
I love myself.

2 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    firstt = Split("I He John She Mary They", " ")
    secondd = Split("love like see find k k", " ")
    object = Split("me him John her Mary them", " ")
    anti = Split("myself himself himself herself herself themselves", " ")
    sss = Split(",s,s,s,s,", ",")
    Input #1, mycount
    Do
    Input #1, strr
    temp = strr
    smany = 0
    For ai = 0 To 5
    ori = Len(temp)
    temp = Replace(temp, firstt(ai), "")
    If Len(temp) <> ori Then smany = smany + 1
    If smany = 1 And ori <> Len(temp) Then s1 = firstt(ai): o1 = object(ai)
    If smany = 2 Then s2 = firstt(ai): o2 = object(ai)
    If smany = 2 Then
    temp = Replace(temp, " ", "")
    Print #2, s1 & " " & temp & " " & o2 & "." & " 或 " & s2 & " " & temp & " " & o1 & ".": Exit For
    End If
    Next
    If smany <> 2 Then
    strr = Split(strr, " ")
    For i = 0 To 2
    For ii = 0 To 5
    If strr(i) = firstt(ii) Then one = strr(i): snum = ii
    If strr(i) = secondd(ii) Then two = strr(i): vnum = ii
    If strr(i) = object(ii) Then three = strr(i): onum = ii
    Next
    Next
    If snum = onum Then three = anti(onum)
    Print #2, one & " " & two & sss(snum) & " " & three & "."
    End If
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除

  2. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, n
    st = Split("I He John She Mary They", " ")
    vt = Split("love like see find", " ")
    ot = Split("me him John her Mary them", " ")
    at = Split("myself himself himself herself herself themselves", " ")
    For w = 1 To Val(n)
    Input #1, x
    c = Split(x): zhuci = "": dongci = "": shouci = ""
    For i = 0 To 2
    For j = 0 To UBound(st)
    If zhuci = "" Then If c(i) = st(j) Then zhuci = st(j): si = j: Exit For
    If shouci = "" Then If c(i) = ot(j) Then shouci = ot(j): oi = j: Exit For
    Next j
    For j = 0 To UBound(vt)
    If c(i) = vt(j) Then dongci = vt(j): Exit For
    Next j
    Next i
    If si = oi Then shouci = at(si)
    If si <> 0 And si <> 5 Then dongci = dongci & "s"
    Print #2, zhuci & " " & dongci & " " & shouci & "."
    Next w
    Close #2
    Close #1
    End
    End Sub

    回覆刪除