A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
26
Task/Multisplit/Go/multisplit.go
Normal file
26
Task/Multisplit/Go/multisplit.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ms(txt string, sep []string) (ans []string) {
|
||||
for txt > "" {
|
||||
sepMatch := ""
|
||||
posMatch := len(txt)
|
||||
for _, s := range sep {
|
||||
if p := strings.Index(txt, s); p >= 0 && p < posMatch {
|
||||
sepMatch = s
|
||||
posMatch = p
|
||||
}
|
||||
}
|
||||
ans = append(ans, txt[:posMatch])
|
||||
txt = txt[posMatch+len(sepMatch):]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("%q\n", ms("a!===b=!=c", []string{"==", "!=", "="}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue