June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
35
Task/Odd-word-problem/VBA/odd-word-problem-1.vba
Normal file
35
Task/Odd-word-problem/VBA/odd-word-problem-1.vba
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
Private Function OddWordFirst(W As String) As String
|
||||
Dim i As Integer, count As Integer, l As Integer, flag As Boolean, temp As String
|
||||
count = 1
|
||||
Do
|
||||
flag = Not flag
|
||||
l = FindNextPunct(i, W) - count + 1
|
||||
If flag Then
|
||||
temp = temp & ExtractWord(W, count, l)
|
||||
Else
|
||||
temp = temp & ReverseWord(W, count, l)
|
||||
End If
|
||||
Loop While count < Len(W)
|
||||
OddWordFirst = temp
|
||||
End Function
|
||||
|
||||
Private Function FindNextPunct(d As Integer, W As String) As Integer
|
||||
Const PUNCT As String = ",;:."
|
||||
Do
|
||||
d = d + 1
|
||||
Loop While InStr(PUNCT, Mid(W, d, 1)) = 0
|
||||
FindNextPunct = d
|
||||
End Function
|
||||
|
||||
Private Function ExtractWord(W As String, c As Integer, i As Integer) As String
|
||||
ExtractWord = Mid(W, c, i)
|
||||
c = c + Len(ExtractWord)
|
||||
End Function
|
||||
|
||||
Private Function ReverseWord(W As String, c As Integer, i As Integer) As String
|
||||
Dim temp As String, sep As String
|
||||
temp = Left(Mid(W, c, i), Len(Mid(W, c, i)) - 1)
|
||||
sep = Right(Mid(W, c, i), 1)
|
||||
ReverseWord = StrReverse(temp) & sep
|
||||
c = c + Len(ReverseWord)
|
||||
End Function
|
||||
39
Task/Odd-word-problem/VBA/odd-word-problem-2.vba
Normal file
39
Task/Odd-word-problem/VBA/odd-word-problem-2.vba
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
Private Function OddWordSecond(Words As String) As String
|
||||
Dim i&, count&, t$, cpt&, j&, l&, d&, f As Boolean
|
||||
Const PUNCT As String = ",;:"
|
||||
For i = 1 To Len(Words)
|
||||
'first word
|
||||
If i = 1 Then
|
||||
cpt = 1
|
||||
Do
|
||||
t = t & Mid(Words, cpt, 1)
|
||||
cpt = cpt + 1
|
||||
Loop While InStr(PUNCT, Mid(Words, cpt, 1)) = 0 And cpt < Len(Words)
|
||||
i = cpt
|
||||
t = t & Mid(Words, i, 1)
|
||||
End If
|
||||
If Right(t, 1) = "." Then Exit For
|
||||
'Odd words ==> reverse
|
||||
While InStr(PUNCT, Mid(Words, cpt + 1, 1)) = 0 And cpt < Len(Words)
|
||||
cpt = cpt + 1
|
||||
Wend
|
||||
l = IIf(f = True, i, i + 1)
|
||||
d = IIf(cpt = Len(Words), cpt - 1, cpt)
|
||||
For j = d To l Step -1
|
||||
t = t & Mid(Words, j, 1)
|
||||
Next
|
||||
If cpt = Len(Words) Then t = t & ".": Exit For
|
||||
f = True
|
||||
i = cpt + 1
|
||||
t = t & Mid(Words, i, 1)
|
||||
'Even words
|
||||
cpt = i + 1
|
||||
t = t & Mid(Words, cpt, 1)
|
||||
Do
|
||||
cpt = cpt + 1
|
||||
t = t & Mid(Words, cpt, 1)
|
||||
Loop While InStr(PUNCT, Mid(Words, cpt, 1)) = 0 And cpt < Len(Words)
|
||||
i = cpt
|
||||
Next
|
||||
OddWordSecond = t
|
||||
End Function
|
||||
11
Task/Odd-word-problem/VBA/odd-word-problem-3.vba
Normal file
11
Task/Odd-word-problem/VBA/odd-word-problem-3.vba
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main()
|
||||
Debug.Print "Input : " & "we,are;not,in,kansas;any,more."
|
||||
Debug.Print "First way : " & OddWordFirst("we,are;not,in,kansas;any,more.")
|
||||
Debug.Print "Second way : " & OddWordSecond("we,are;not,in,kansas;any,more.")
|
||||
Debug.Print ""
|
||||
Debug.Print "Input : " & "what,is,the;meaning,of:life."
|
||||
Debug.Print "First way : " & OddWordFirst("what,is,the;meaning,of:life.")
|
||||
Debug.Print "Second way : " & OddWordSecond("what,is,the;meaning,of:life.")
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue