medmond919

Go Example #2

Mar 26th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strings"
  6. )
  7.  
  8. func main() {
  9.     s := "Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can."
  10.     firstOnly := make(map[int]struct{})
  11.     for _, i := range []int{1, 5, 6, 7, 8, 9, 15, 16, 19} {
  12.         firstOnly[i] = struct{}{}
  13.     }
  14.     result := make(map[string]int)
  15.     for i, w := range strings.Split(s, " ") {
  16.         var n int
  17.         if _, ok := firstOnly[i+1]; ok {
  18.             n = 1
  19.         } else {
  20.             n = 2
  21.         }
  22.         result[w[:n]] = i + 1
  23.     }
  24.     fmt.Println(result)
  25. }
Advertisement
Add Comment
Please, Sign In to add comment