题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
package main
import ( "fmt" "os" "bufio" "strings" )
func main() { input := bufio.NewScanner(os.Stdin) input.Scan() s := input.Text() li := make([]byte, 0) for i := 0; i < len(s); i++ { if s[i] >= 'a' && s[i] <= 'z' { li = append(li, s[i]) } else if s[i] >= 'A' && s[i] <= 'Z' { li = append(li, s[i]) } else { li = append(li, ' ') } } s = string(li) l2 := strings.Split(s, " ") for i := 0; i < len(l2); i++ { fmt.Printf("%s ", l2[len(l2)-i-1]) } }