Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
70
Task/Abbreviations-easy/FreeBASIC/abbreviations-easy.basic
Normal file
70
Task/Abbreviations-easy/FreeBASIC/abbreviations-easy.basic
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
Dim As String table = "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy " _
|
||||
+ "COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find " _
|
||||
+ "NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput " _
|
||||
+ "Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO " _
|
||||
+ "MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT " _
|
||||
+ "READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT " _
|
||||
+ "RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up"
|
||||
|
||||
Function NextWord(Byref posic As Integer, text As String) As String
|
||||
' skip spaces
|
||||
While posic <= Len(text) And Mid(text, posic, 1) = " "
|
||||
posic += 1
|
||||
Wend
|
||||
' get the word
|
||||
Dim word As String = ""
|
||||
While posic <= Len(text) And Mid(text, posic, 1) <> " "
|
||||
word += Mid(text, posic, 1)
|
||||
posic += 1
|
||||
Wend
|
||||
Return word
|
||||
End Function
|
||||
|
||||
Function MinABLength(comando As String) As Integer
|
||||
Dim ab_min As Integer = 1
|
||||
While ab_min <= Len(comando) And Ucase(Mid(comando, ab_min, 1)) = Mid(comando, ab_min, 1)
|
||||
ab_min += 1
|
||||
Wend
|
||||
Return ab_min - 1
|
||||
End Function
|
||||
|
||||
Function Expand(table As String, word As String) As String
|
||||
If Len(word) = 0 Then
|
||||
Return ""
|
||||
Else
|
||||
Dim As Integer word_len = Len(word)
|
||||
Dim As String result = "*error*"
|
||||
Dim As Integer posic = 1
|
||||
Do
|
||||
Dim As String comando = NextWord(posic, table)
|
||||
If Len(comando) = 0 Then
|
||||
Exit Do
|
||||
Elseif word_len < MinABLength(comando) Or word_len > Len(comando) Then
|
||||
Continue Do
|
||||
Elseif Ucase(word) = Ucase(Left(comando, word_len)) Then
|
||||
result = Ucase(comando)
|
||||
Exit Do
|
||||
End If
|
||||
Loop
|
||||
Return result
|
||||
End If
|
||||
End Function
|
||||
|
||||
Sub TestExpand(words As String, table As String)
|
||||
Dim As String word, results = "", separator = ""
|
||||
Dim As Integer posic = 1
|
||||
Do
|
||||
word = NextWord(posic, words)
|
||||
If Len(word) = 0 Then Exit Do
|
||||
results += separator + Expand(table, word)
|
||||
separator = " "
|
||||
Loop
|
||||
Print "Input: "; words
|
||||
Print "Output: "; results
|
||||
End Sub
|
||||
|
||||
' task test cases
|
||||
TestExpand("riG rePEAT copies put mo rest types fup. 6 poweRin", table)
|
||||
TestExpand("", table)
|
||||
|
||||
Sleep
|
||||
|
|
@ -1,27 +1,41 @@
|
|||
/*REXX program validates a user "word" against a "command table" with abbreviations.*/
|
||||
parse arg uw /*obtain optional arguments from the CL*/
|
||||
if uw='' then uw= 'riG rePEAT copies put mo rest types fup. 6 poweRin'
|
||||
say 'user words: ' uw
|
||||
|
||||
@= 'Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy' ,
|
||||
'COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find' ,
|
||||
'NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput' ,
|
||||
'Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO' ,
|
||||
'MErge MOve MODify MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT' ,
|
||||
'READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT' ,
|
||||
'RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up'
|
||||
|
||||
say 'full words: ' validate(uw) /*display the result(s) to the terminal*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
validate: procedure expose @; arg x; upper @ /*ARG capitalizes all the X words. */
|
||||
$= /*initialize the return string to null.*/
|
||||
do j=1 to words(x); _=word(x, j) /*obtain a word from the X list. */
|
||||
do k=1 to words(@); a=word(@, k) /*get a legitimate command name from @.*/
|
||||
L=verify(_, 'abcdefghijklmnopqrstuvwxyz', "M") /*maybe get abbrev's len.*/
|
||||
if L==0 then L=length(_) /*0? Command name can't be abbreviated*/
|
||||
if abbrev(a, _, L) then do; $=$ a; iterate j; end /*is valid abbrev?*/
|
||||
end /*k*/
|
||||
$=$ '*error*' /*processed the whole list, not valid. */
|
||||
end /*j*/
|
||||
return strip($) /*elide the superfluous leading blank. */
|
||||
/*REXX program validates user words against a "command table" with abbreviations.*/
|
||||
Parse Arg userwords /*obtain optional arguments from the command line */
|
||||
If userwords='' Then /* nothing specified, use default list from task */
|
||||
userwords= 'riG rePEAT copies put mo rest types fup. 6 poweRin'
|
||||
Say 'user words: ' userwords
|
||||
keyws='Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy',
|
||||
'COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find',
|
||||
'NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput',
|
||||
'Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase LPrefix MACRO',
|
||||
'MErge MOve MODify MSG Next Overlay PARSE PREServe PURge PUT PUTD Query QUIT',
|
||||
'READ RECover REFRESH RENum REPeat Replace CReplace RESet RESTore RGTLEFT',
|
||||
'RIght LEft SAVE SET SHift SI SORT SOS STAck STATus TOP TRAnsfer Type Up'
|
||||
Say 'full words: ' validate(userwords) /*display the result(s) To the terminal*/
|
||||
Exit /*stick a fork in it, we're all Done. */
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
validate: Procedure Expose keyws
|
||||
Arg userwords /* Arg = Parse Upper Arg get userwords in uppercase */
|
||||
res='' /* initialize the return string To null */
|
||||
Do j=1 To words(userwords) /* loop through userwords */
|
||||
uword=word(userwords,j) /* get next userword */
|
||||
Do k=1 To words(keyws) /* loop through all keywords */
|
||||
keyw=word(keyws,k)
|
||||
L=verify(keyw,'abcdefghijklmnopqrstuvwxyz','M') /* pos. of first lowercase ch*/
|
||||
If L==0 Then /* keyword is all uppercase */
|
||||
L=length(keyw) /* we need L characters for a match */
|
||||
Else
|
||||
L=L-1 /* number of uppercase characters */
|
||||
If abbrev(translate(keyw),uword,L) Then Do /* uword is an abbreviation */
|
||||
res=res keyw /* add the matching keyword To the result string */
|
||||
iterate j /* and proceed with the next userword if any */
|
||||
End
|
||||
End
|
||||
res=res '*error*' /* no match found. indicate error */
|
||||
End
|
||||
Return strip(res) /* get rid of leading böank */
|
||||
syntaxhighlight>
|
||||
{{out|output|text= when using the default input:}}
|
||||
<pre>
|
||||
user words: riG rePEAT copies put mo rest types fup. 6 poweRin
|
||||
full words: RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT
|
||||
</pre>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue