Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
31
Task/Determine-sentence-type/Go/determine-sentence-type.go
Normal file
31
Task/Determine-sentence-type/Go/determine-sentence-type.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func sentenceType(s string) string {
|
||||
if len(s) == 0 {
|
||||
return ""
|
||||
}
|
||||
var types []string
|
||||
for _, c := range s {
|
||||
if c == '?' {
|
||||
types = append(types, "Q")
|
||||
} else if c == '!' {
|
||||
types = append(types, "E")
|
||||
} else if c == '.' {
|
||||
types = append(types, "S")
|
||||
}
|
||||
}
|
||||
if strings.IndexByte("?!.", s[len(s)-1]) == -1 {
|
||||
types = append(types, "N")
|
||||
}
|
||||
return strings.Join(types, "|")
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := "hi there, how are you today? I'd like to present to you the washing machine 9001. You have been nominated to win one of these! Just make sure you don't break it"
|
||||
fmt.Println(sentenceType(s))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue