Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Rep-string/Go/rep-string.go
Normal file
38
Task/Rep-string/Go/rep-string.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func rep(s string) int {
|
||||
for x := len(s) / 2; x > 0; x-- {
|
||||
if strings.HasPrefix(s, s[x:]) {
|
||||
return x
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
const m = `
|
||||
1001110011
|
||||
1110111011
|
||||
0010010010
|
||||
1010101010
|
||||
1111111111
|
||||
0100101101
|
||||
0100100
|
||||
101
|
||||
11
|
||||
00
|
||||
1`
|
||||
|
||||
func main() {
|
||||
for _, s := range strings.Fields(m) {
|
||||
if n := rep(s); n > 0 {
|
||||
fmt.Printf("%q %d rep-string %q\n", s, n, s[:n])
|
||||
} else {
|
||||
fmt.Printf("%q not a rep-string\n", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue