Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Test-a-function/FreeBASIC/test-a-function.basic
Normal file
42
Task/Test-a-function/FreeBASIC/test-a-function.basic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
Sub StrReverse(Byref text As String)
|
||||
Dim As Integer x, lt = Len(text)
|
||||
For x = 0 To lt Shr 1 - 1
|
||||
Swap text[x], text[lt - x - 1]
|
||||
Next x
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Replace(Byref T As String, Byref I As String, Byref S As String, Byval A As Integer = 1)
|
||||
Var p = Instr(A, T, I), li = Len(I), ls = Len(S) : If li = ls Then li = 0
|
||||
Do While p
|
||||
If li Then T = Left(T, p - 1) & S & Mid(T, p + li) Else Mid(T, p) = S
|
||||
p = Instr(p + ls, T, I)
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
Function IsPalindrome(Byval txt As String) As Boolean
|
||||
Dim As String tempTxt = Lcase(txt), copyTxt = Lcase(txt)
|
||||
Replace(tempTxt, " ", "")
|
||||
Replace(copyTxt, " ", "")
|
||||
|
||||
StrReverse(tempTxt)
|
||||
If tempTxt = copyTxt Then
|
||||
Color 10
|
||||
Return true
|
||||
Else
|
||||
Color 12
|
||||
Return false
|
||||
End If
|
||||
End Function
|
||||
|
||||
'--- Programa Principal ---
|
||||
Dim As String a(10) => {"abba", "mom", "dennis sinned", "Un roc lamina l animal cornu", _
|
||||
"palindrome", "ba _ ab", "racecars", "racecar", "wombat", "in girum imus nocte et consumimur igni"}
|
||||
|
||||
Print !"¨Pal¡ndromos?\n"
|
||||
For i As Byte = 0 To Ubound(a)-1
|
||||
Print a(i) & " -> ";
|
||||
Print IsPalindrome((a(i)))
|
||||
Color 7
|
||||
Next i
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue