Skip to content

Instantly share code, notes, and snippets.

@angch
Created August 19, 2015 15:07
Show Gist options
  • Save angch/9a42b5c87fe075aba162 to your computer and use it in GitHub Desktop.
Save angch/9a42b5c87fe075aba162 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"sort"
"strconv"
"strings"
)
func main() {
dict := make(map[string]bool)
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
lines := scanner.Text()
nlines, _ := strconv.Atoi(lines)
re, _ := regexp.Compile("(?i)[a-z]+")
for ; nlines > 0; nlines-- {
scanner.Scan()
line := scanner.Text()
words := re.FindAllStringSubmatch(line, -1)
for _, word := range words {
lword := strings.ToLower(word[0])
if re.MatchString(lword) {
dict[lword] = true
}
}
}
keys := make([]string, 0, len(dict))
for k, _ := range dict {
keys = append(keys, k)
}
sort.Strings(keys)
fmt.Println(strings.Join(keys, "\n"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment