Created
April 3, 2017 15:59
-
-
Save rupalbarman/0630c5a859f11b29ce7a33c642010da7 to your computer and use it in GitHub Desktop.
Helpful code snippets in GoLang for competitive coding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "index/suffixarray" | |
| ) | |
| func main() { | |
| //readn_arr() | |
| suffixarray_usage() | |
| } | |
| func suffixarray_usage() { | |
| index:= suffixarray.New([]byte("HelloIamRupalIamiam")) | |
| fmt.Println("search for Hell") | |
| items:= index.Lookup([]byte("Hell"), 1) //n means num of occurances to find | |
| // -1 means all | |
| for i, v:= range items { | |
| fmt.Println(i, v) | |
| } | |
| fmt.Println("search for Rupal") | |
| items= index.Lookup([]byte("Rupal"), -1) | |
| for i, v:= range items { | |
| fmt.Println(i, v) | |
| } | |
| fmt.Println("search for Iam") | |
| items= index.Lookup([]byte("Iam"), -1) | |
| for i, v:= range items { | |
| fmt.Println(i, v) | |
| } | |
| //get original string we made the index of | |
| fmt.Println("Index:", string(index.Bytes())) //return []byte | |
| } | |
| func readn_arr() { | |
| var n int | |
| fmt.Scanf("%d", &n) | |
| a:= make([]int, n) | |
| for i:=0; i<n; i++ { | |
| fmt.Scanf("%d", &a[i]) | |
| } | |
| fmt.Println(a) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment