2017-07-07 14:44:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "io"
|
|
|
|
import "log"
|
|
|
|
import "os"
|
|
|
|
import "bufio"
|
|
|
|
import "strings"
|
|
|
|
|
2017-07-07 14:55:55 +00:00
|
|
|
var PUNCTUATION = []string{".", ",", "\"", "—", "-", "/"}
|
|
|
|
|
2017-07-07 14:44:17 +00:00
|
|
|
func longest(r io.Reader) string {
|
|
|
|
lw := ""
|
|
|
|
s := bufio.NewScanner(r)
|
|
|
|
s.Split(bufio.ScanWords)
|
|
|
|
for s.Scan() {
|
|
|
|
word := s.Text()
|
|
|
|
word = strings.ToLower(word)
|
2017-07-07 14:55:55 +00:00
|
|
|
for _, c := range PUNCTUATION {
|
|
|
|
word = strings.Replace(word, c, " ", -1)
|
|
|
|
}
|
|
|
|
for _, word := range strings.Fields(word) {
|
2017-07-07 14:44:17 +00:00
|
|
|
if len(word) > len(lw) {
|
2017-07-07 14:55:55 +00:00
|
|
|
lw = word
|
2017-07-07 14:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lw
|
|
|
|
}
|
|
|
|
|
|
|
|
func openFile(path *string) *os.File {
|
|
|
|
f, err := os.Open(os.Args[1])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) <= 1 {
|
|
|
|
log.Fatalln("Missing file")
|
|
|
|
}
|
|
|
|
f := openFile(&os.Args[1])
|
|
|
|
|
|
|
|
fmt.Println(longest(f))
|
|
|
|
}
|