medmond919 icon

Go Example #2

medmond919 | PRO | 03/26/18 03:52:09 PM UTC | 0 ⭐ | 282 👁️ | Never ⏰ | []
Go |

530 B

|

None

|

0 👍

/

0 👎

package main
 
import (
    "fmt"
    "strings"
)
 
func main() {
    s := "Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can."
    firstOnly := make(map[int]struct{})
    for _, i := range []int{1, 5, 6, 7, 8, 9, 15, 16, 19} {
        firstOnly[i] = struct{}{}
    }
    result := make(map[string]int)
    for i, w := range strings.Split(s, " ") {
        var n int
        if _, ok := firstOnly[i+1]; ok {
            n = 1
        } else {
            n = 2
        }
        result[w[:n]] = i + 1
    }
    fmt.Println(result)
}

Comments