Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
18
Task/String-matching/ALGOL-68/string-matching.alg
Normal file
18
Task/String-matching/ALGOL-68/string-matching.alg
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# define some appropriate OPerators #
|
||||
PRIO STARTSWITH = 5, ENDSWITH = 5;
|
||||
OP STARTSWITH = (STRING str, prefix)BOOL: # assuming LWB = 1 #
|
||||
IF UPB str < UPB prefix THEN FALSE ELSE str[:UPB prefix]=prefix FI;
|
||||
OP ENDSWITH = (STRING str, suffix)BOOL: # assuming LWB = 1 #
|
||||
IF UPB str < UPB suffix THEN FALSE ELSE str[UPB str-UPB suffix+1:]=suffix FI;
|
||||
|
||||
INT loc, loc2;
|
||||
|
||||
print((
|
||||
"abcd" STARTSWITH "ab", # returns TRUE #
|
||||
"abcd" ENDSWITH "zn", # returns FALSE #
|
||||
string in string("bb",loc,"abab"), # returns FALSE #
|
||||
string in string("ab",loc,"abab"), # returns TRUE #
|
||||
(string in string("bb",loc,"abab")|loc|-1), # returns -1 #
|
||||
(string in string("ab",loc,"abab")|loc|-1), # returns +1 #
|
||||
(string in string("ab",loc2,"abab"[loc+1:])|loc+loc2|-1) # returns +3 #
|
||||
))
|
||||
Loading…
Add table
Add a link
Reference in a new issue