Skip to content

Instantly share code, notes, and snippets.

@ukyo
Created August 26, 2011 09:10
Show Gist options
  • Save ukyo/1173023 to your computer and use it in GitHub Desktop.
Save ukyo/1173023 to your computer and use it in GitHub Desktop.
sais go
package main
import (
"fmt"
"os"
"io/ioutil"
)
func getCounts() {
}
func getBuckets() {
}
func getLS(s string) []bool {
l := len(s)
t := make([]bool, len(s))
t[l - 1] = true
for i := l - 1; i > 0; i-- {
switch {
case s[i - 1] == s[i]:
t[i - 1] = t[i]
default:
t[i - 1] = s[i - 1] < s[i]
}
}
return t
}
func main() {
data, _ := ioutil.ReadAll(os.Stdin)
s := string(data[:len(data) - 1]) + "$"
t := getLS(s[:])
LS := map[bool]string{false: "L", true: "S"}
fmt.Println(s)
for _, v := range t {
fmt.Printf("%v", LS[v])
}
fmt.Println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment